[PATCH 0/2] drivers/rng: add Amlogic hardware RNG driver

The first patch simplifies the Kconfig for hardware RNG drivers and enables the Sandbox RNG driver for all Sandbox instances.
The second introduces a hardware random number generator driver for Amlogic SOCs. This second patch had been sent before but the preceding patch was missing.
Heinrich Schuchardt (2): drivers/rng: simplify Kconfig drivers/rng: add Amlogic hardware RNG driver
configs/sandbox64_defconfig | 1 - configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 17 ++++- drivers/rng/Makefile | 1 + drivers/rng/meson-rng.c | 120 ++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 drivers/rng/meson-rng.c
-- 2.25.1

For all sandbox systems with DM_RNG we enable RNG_SANDBOX. So we can simply set the default to yes.
All rng drivers depend on DM_RNG. Use a single 'if' instead of individual dependencies. Now 'make menuconfig' shows the individual drivers neatly indented under the DM_RNG entry.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de --- configs/sandbox64_defconfig | 1 - configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 9 +++++++-- 3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index d1c94b65a1..71a4d7fccb 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -169,7 +169,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y -CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_SANDBOX_SERIAL=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 45b5475b79..f96891ecae 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -189,7 +189,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y -CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_DEBUG_UART_SANDBOX=y diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 893b89d49b..c1aa43b823 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -6,16 +6,21 @@ config DM_RNG This interface is used to initialise the rng device and to read the random seed from the device.
+if DM_RNG + config RNG_SANDBOX bool "Sandbox random number generator" - depends on SANDBOX && DM_RNG + depends on SANDBOX + default y help Enable random number generator for sandbox. This is an emulation of a rng device.
config RNG_STM32MP1 bool "Enable random number generator for STM32MP1" - depends on ARCH_STM32MP && DM_RNG + depends on ARCH_STM32MP default n help Enable STM32MP1 rng driver. + +endif -- 2.25.1

Hi Heinrich,
From: U-Boot u-boot-bounces@lists.denx.de On Behalf Of Heinrich Schuchardt Sent: mercredi 4 mars 2020 02:18
For all sandbox systems with DM_RNG we enable RNG_SANDBOX. So we can simply set the default to yes.
All rng drivers depend on DM_RNG. Use a single 'if' instead of individual dependencies. Now 'make menuconfig' shows the individual drivers neatly indented under the DM_RNG entry.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de
Reviewed-by: Patrick Delaunay patrick.delaunay@st.com
Regards Patrick
configs/sandbox64_defconfig | 1 - configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 9 +++++++-- 3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index d1c94b65a1..71a4d7fccb 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -169,7 +169,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y - CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_SANDBOX_SERIAL=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 45b5475b79..f96891ecae 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -189,7 +189,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y - CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_DEBUG_UART_SANDBOX=y diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 893b89d49b..c1aa43b823 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -6,16 +6,21 @@ config DM_RNG This interface is used to initialise the rng device and to read the random seed from the device.
+if DM_RNG
config RNG_SANDBOX bool "Sandbox random number generator"
- depends on SANDBOX && DM_RNG
- depends on SANDBOX
- default y help Enable random number generator for sandbox. This is an emulation of a rng device.
config RNG_STM32MP1 bool "Enable random number generator for STM32MP1"
- depends on ARCH_STM32MP && DM_RNG
- depends on ARCH_STM32MP default n help Enable STM32MP1 rng driver.
+endif
2.25.1

On Wed, 4 Mar 2020 at 06:47, Heinrich Schuchardt xypron.glpk@gmx.de wrote:
For all sandbox systems with DM_RNG we enable RNG_SANDBOX. So we can simply set the default to yes.
All rng drivers depend on DM_RNG. Use a single 'if' instead of individual dependencies. Now 'make menuconfig' shows the individual drivers neatly indented under the DM_RNG entry.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de
Reviewed-by: Sughosh Ganu sughosh.ganu@linaro.org
-sughosh
configs/sandbox64_defconfig | 1 -
configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 9 +++++++-- 3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index d1c94b65a1..71a4d7fccb 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -169,7 +169,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y -CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_SANDBOX_SERIAL=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 45b5475b79..f96891ecae 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -189,7 +189,6 @@ CONFIG_REMOTEPROC_SANDBOX=y CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y -CONFIG_RNG_SANDBOX=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_DEBUG_UART_SANDBOX=y diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 893b89d49b..c1aa43b823 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -6,16 +6,21 @@ config DM_RNG This interface is used to initialise the rng device and to read the random seed from the device.
+if DM_RNG
config RNG_SANDBOX bool "Sandbox random number generator"
depends on SANDBOX && DM_RNG
depends on SANDBOX
default y help Enable random number generator for sandbox. This is an emulation of a rng device.
config RNG_STM32MP1 bool "Enable random number generator for STM32MP1"
depends on ARCH_STM32MP && DM_RNG
depends on ARCH_STM32MP default n help Enable STM32MP1 rng driver.
+endif
2.25.1

hi Tom,
On Wed, 4 Mar 2020 at 06:47, Heinrich Schuchardt xypron.glpk@gmx.de wrote:
For all sandbox systems with DM_RNG we enable RNG_SANDBOX. So we can simply set the default to yes.
All rng drivers depend on DM_RNG. Use a single 'if' instead of individual dependencies. Now 'make menuconfig' shows the individual drivers neatly indented under the DM_RNG entry.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de
---
Can you please pick up the two patches of the series directly. Thanks.
-sughosh

On 3/7/20 7:58 AM, Sughosh Ganu wrote:
hi Tom,
On Wed, 4 Mar 2020 at 06:47, Heinrich Schuchardt <xypron.glpk@gmx.de mailto:xypron.glpk@gmx.de> wrote:
For all sandbox systems with DM_RNG we enable RNG_SANDBOX. So we can simply set the default to yes. All rng drivers depend on DM_RNG. Use a single 'if' instead of individual dependencies. Now 'make menuconfig' shows the individual drivers neatly indented under the DM_RNG entry. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de <mailto:xypron.glpk@gmx.de>> ---
Can you please pick up the two patches of the series directly. Thanks.
-sughosh
This series has been applied to origin/master (bc40eb278b0c14b990556ea).
Best regards
Heinrich

Add support for the hardware random number generator of Amlogic SOCs.
Signed-off-by: Heinrich Schuchardt xypron.glpk@gmx.de Reviewed-by: Neil Armstrong narmstrong@baylibre.com Reviewed-by: Sughosh Ganu sughosh.ganu@linaro.org --- Resent --- drivers/rng/Kconfig | 8 +++ drivers/rng/Makefile | 1 + drivers/rng/meson-rng.c | 120 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 drivers/rng/meson-rng.c
diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index c1aa43b823..edb6152bb9 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -8,6 +8,14 @@ config DM_RNG
if DM_RNG
+config RNG_MESON + bool "Amlogic Meson Random Number Generator support" + depends on ARCH_MESON + default y + help + Enable support for hardware random number generator + of Amlogic Meson SoCs. + config RNG_SANDBOX bool "Sandbox random number generator" depends on SANDBOX diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile index 3517005541..6a8a66779b 100644 --- a/drivers/rng/Makefile +++ b/drivers/rng/Makefile @@ -4,5 +4,6 @@ #
obj-$(CONFIG_DM_RNG) += rng-uclass.o +obj-$(CONFIG_RNG_MESON) += meson-rng.o obj-$(CONFIG_RNG_SANDBOX) += sandbox_rng.o obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o diff --git a/drivers/rng/meson-rng.c b/drivers/rng/meson-rng.c new file mode 100644 index 0000000000..4b81a62353 --- /dev/null +++ b/drivers/rng/meson-rng.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2020, Heinrich Schuchardt xypron.glpk@gmx.de + * + * Driver for Amlogic hardware random number generator + */ + +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <rng.h> +#include <asm/io.h> + +struct meson_rng_platdata { + fdt_addr_t base; + struct clk clk; +}; + +/** + * meson_rng_read() - fill buffer with random bytes + * + * @buffer: buffer to receive data + * @size: size of buffer + * + * Return: 0 + */ +static int meson_rng_read(struct udevice *dev, void *data, size_t len) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + char *buffer = (char *)data; + + while (len) { + u32 rand = readl(pdata->base); + size_t step; + + if (len >= 4) + step = 4; + else + step = len; + memcpy(buffer, &rand, step); + buffer += step; + len -= step; + } + return 0; +} + +/** + * meson_rng_probe() - probe rng device + * + * @dev: device + * Return: 0 if ok + */ +static int meson_rng_probe(struct udevice *dev) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + int err; + + err = clk_enable(&pdata->clk); + if (err) + return err; + + return 0; +} + +/** + * meson_rng_remove() - deinitialize rng device + * + * @dev: device + * Return: 0 if ok + */ +static int meson_rng_remove(struct udevice *dev) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + + return clk_disable(&pdata->clk); +} + +/** + * meson_rng_ofdata_to_platdata() - transfer device tree data to plaform data + * + * @dev: device + * Return: 0 if ok + */ +static int meson_rng_ofdata_to_platdata(struct udevice *dev) +{ + struct meson_rng_platdata *pdata = dev_get_platdata(dev); + int err; + + pdata->base = dev_read_addr(dev); + if (!pdata->base) + return -ENODEV; + + err = clk_get_by_name(dev, "core", &pdata->clk); + if (err) + return err; + + return 0; +} + +static const struct dm_rng_ops meson_rng_ops = { + .read = meson_rng_read, +}; + +static const struct udevice_id meson_rng_match[] = { + { + .compatible = "amlogic,meson-rng", + }, + {}, +}; + +U_BOOT_DRIVER(meson_rng) = { + .name = "meson-rng", + .id = UCLASS_RNG, + .of_match = meson_rng_match, + .ops = &meson_rng_ops, + .probe = meson_rng_probe, + .remove = meson_rng_remove, + .platdata_auto_alloc_size = sizeof(struct meson_rng_platdata), + .ofdata_to_platdata = meson_rng_ofdata_to_platdata, +}; -- 2.25.1

On 04/03/2020 02:17, Heinrich Schuchardt wrote:
The first patch simplifies the Kconfig for hardware RNG drivers and enables the Sandbox RNG driver for all Sandbox instances.
The second introduces a hardware random number generator driver for Amlogic SOCs. This second patch had been sent before but the preceding patch was missing.
Heinrich Schuchardt (2): drivers/rng: simplify Kconfig drivers/rng: add Amlogic hardware RNG driver
configs/sandbox64_defconfig | 1 - configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 17 ++++- drivers/rng/Makefile | 1 + drivers/rng/meson-rng.c | 120 ++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 drivers/rng/meson-rng.c
-- 2.25.1
Hi Sughosh,
Should I take this serie in my tree ?
Neil

On 3/27/20 2:30 PM, Neil Armstrong wrote:
On 04/03/2020 02:17, Heinrich Schuchardt wrote:
The first patch simplifies the Kconfig for hardware RNG drivers and enables the Sandbox RNG driver for all Sandbox instances.
The second introduces a hardware random number generator driver for Amlogic SOCs. This second patch had been sent before but the preceding patch was missing.
Heinrich Schuchardt (2): drivers/rng: simplify Kconfig drivers/rng: add Amlogic hardware RNG driver
configs/sandbox64_defconfig | 1 - configs/sandbox_defconfig | 1 - drivers/rng/Kconfig | 17 ++++- drivers/rng/Makefile | 1 + drivers/rng/meson-rng.c | 120 ++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 drivers/rng/meson-rng.c
-- 2.25.1
Hi Sughosh,
Should I take this series in my tree ?
Neil
Hello Neil,
the two patches have been merged with bc40eb278b0c14b99055 with the efi-2020-04-rc4-3 pull request.
Best regards
Heinrich
participants (4)
-
Heinrich Schuchardt
-
Neil Armstrong
-
Patrick DELAUNAY
-
Sughosh Ganu