Merge tag 'u-boot-atmel-fixes-2021.01-b' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / lib / efi_loader / efi_rng.c
index a1d0ec8..8bdadad 100644 (file)
@@ -3,10 +3,13 @@
  * Copyright (c) 2019, Linaro Limited
  */
 
+#define LOG_CATEGORY LOGC_EFI
+
 #include <common.h>
 #include <dm.h>
 #include <efi_loader.h>
 #include <efi_rng.h>
+#include <log.h>
 #include <rng.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -143,7 +146,33 @@ back:
        return EFI_EXIT(status);
 }
 
-const struct efi_rng_protocol efi_rng_protocol = {
+static const struct efi_rng_protocol efi_rng_protocol = {
        .get_info = rng_getinfo,
        .get_rng = getrng,
 };
+
+/**
+ * efi_rng_register() - register EFI_RNG_PROTOCOL
+ *
+ * If a RNG device is available, the Random Number Generator Protocol is
+ * registered.
+ *
+ * Return:     An error status is only returned if adding the protocol fails.
+ */
+efi_status_t efi_rng_register(void)
+{
+       efi_status_t ret;
+       struct udevice *dev;
+
+       ret = platform_get_rng_device(&dev);
+       if (ret != EFI_SUCCESS) {
+               log_warning("Missing RNG device for EFI_RNG_PROTOCOL\n");
+               return EFI_SUCCESS;
+       }
+       ret = efi_add_protocol(efi_root, &efi_guid_rng_protocol,
+                              (void *)&efi_rng_protocol);
+       if (ret != EFI_SUCCESS)
+               log_err("Cannot install EFI_RNG_PROTOCOL\n");
+
+       return ret;
+}