From b9f31c0e40fabb5294a9bcc22624e30a139d7d09 Mon Sep 17 00:00:00 2001 From: "Duy Phuong Hoang. Nguyen" Date: Tue, 18 Jun 2024 12:17:23 +0700 Subject: [PATCH] drivers: entropy: Initial support for trng driver of RA8 Initial commit for entropy support on RA8 - drivers: entropy: implementation for TRNG driver of RA8x1 - dts: arm: add device node for trng of RA8x1 - boards: arm: enable support zephyr_entropy for ek_ra8m1 and update board documentation Signed-off-by: The Nguyen Signed-off-by: Duy Phuong Hoang. Nguyen --- boards/renesas/ek_ra8m1/doc/index.rst | 2 + boards/renesas/ek_ra8m1/ek_ra8m1.dts | 5 ++ drivers/entropy/CMakeLists.txt | 19 +++---- drivers/entropy/Kconfig | 1 + drivers/entropy/Kconfig.renesas_ra | 13 +++++ drivers/entropy/entropy_renesas_ra.c | 49 +++++++++++++++++++ dts/arm/renesas/ra/ra8/ra8x1.dtsi | 4 ++ .../rng/renesas,ra-rsip-e51a-trng.yaml | 8 +++ modules/Kconfig.renesas_fsp | 16 ++++++ 9 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 drivers/entropy/Kconfig.renesas_ra create mode 100644 drivers/entropy/entropy_renesas_ra.c create mode 100644 dts/bindings/rng/renesas,ra-rsip-e51a-trng.yaml diff --git a/boards/renesas/ek_ra8m1/doc/index.rst b/boards/renesas/ek_ra8m1/doc/index.rst index d0c8dba907c..b58f513af99 100644 --- a/boards/renesas/ek_ra8m1/doc/index.rst +++ b/boards/renesas/ek_ra8m1/doc/index.rst @@ -100,6 +100,8 @@ The below features are currently supported on Zephyr OS for EK-RA8M1 board: +-----------+------------+----------------------+ | I2C | on-chip | i2c | +-----------+------------+----------------------+ +| ENTROPY | on-chip | entropy | ++-----------+------------+----------------------+ Other hardware features are currently not supported by the port. diff --git a/boards/renesas/ek_ra8m1/ek_ra8m1.dts b/boards/renesas/ek_ra8m1/ek_ra8m1.dts index 193b706612f..ac29d191e3e 100644 --- a/boards/renesas/ek_ra8m1/ek_ra8m1.dts +++ b/boards/renesas/ek_ra8m1/ek_ra8m1.dts @@ -19,6 +19,7 @@ zephyr,flash = &flash0; zephyr,console = &uart9; zephyr,shell-uart = &uart9; + zephyr,entropy = &trng; }; leds { @@ -158,3 +159,7 @@ mikrobus_serial: &uart3 {}; pinctrl-0 = <&adc0_default>; pinctrl-names = "default"; }; + +&trng { + status = "okay"; +}; diff --git a/drivers/entropy/CMakeLists.txt b/drivers/entropy/CMakeLists.txt index aa867650611..8a67fc3a03e 100644 --- a/drivers/entropy/CMakeLists.txt +++ b/drivers/entropy/CMakeLists.txt @@ -25,14 +25,15 @@ if(CONFIG_FAKE_ENTROPY_NATIVE_POSIX) endif() endif() -zephyr_library_sources_ifdef(CONFIG_USERSPACE entropy_handlers.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_RV32M1_TRNG entropy_rv32m1_trng.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_TRNG entropy_gecko_trng.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_NEORV32_TRNG entropy_neorv32_trng.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_BT_HCI entropy_bt_hci.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_SE entropy_gecko_se.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_PSA_CRYPTO_RNG entropy_psa_crypto.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_NPCX_DRBG entropy_npcx_drbg.c) -zephyr_library_sources_ifdef(CONFIG_ENTROPY_MAX32_TRNG entropy_max32.c) +zephyr_library_sources_ifdef(CONFIG_USERSPACE entropy_handlers.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_RV32M1_TRNG entropy_rv32m1_trng.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_TRNG entropy_gecko_trng.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_NEORV32_TRNG entropy_neorv32_trng.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_BT_HCI entropy_bt_hci.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_SE entropy_gecko_se.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_PSA_CRYPTO_RNG entropy_psa_crypto.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_NPCX_DRBG entropy_npcx_drbg.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_MAX32_TRNG entropy_max32.c) +zephyr_library_sources_ifdef(CONFIG_ENTROPY_RENESAS_RA_RSIP_E51A_TRNG entropy_renesas_ra.c) zephyr_library_link_libraries_ifdef(CONFIG_BUILD_WITH_TFM tfm_api) diff --git a/drivers/entropy/Kconfig b/drivers/entropy/Kconfig index 21bb7bdca59..debd0f8d7a1 100644 --- a/drivers/entropy/Kconfig +++ b/drivers/entropy/Kconfig @@ -37,6 +37,7 @@ source "drivers/entropy/Kconfig.bt_hci" source "drivers/entropy/Kconfig.psa_crypto" source "drivers/entropy/Kconfig.npcx" source "drivers/entropy/Kconfig.max32" +source "drivers/entropy/Kconfig.renesas_ra" config ENTROPY_HAS_DRIVER bool diff --git a/drivers/entropy/Kconfig.renesas_ra b/drivers/entropy/Kconfig.renesas_ra new file mode 100644 index 00000000000..c212e7ba51b --- /dev/null +++ b/drivers/entropy/Kconfig.renesas_ra @@ -0,0 +1,13 @@ +# Copyright (c) 2024 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +# Renesas RA entropy generator driver configuration + +config ENTROPY_RENESAS_RA_RSIP_E51A_TRNG + bool "Renesas RA RSIP-E51A TRNG driver" + default y + depends on DT_HAS_RENESAS_RA_RSIP_E51A_TRNG_ENABLED + select ENTROPY_HAS_DRIVER + select USE_RA_FSP_SCE + help + This option enables the Renesas RA RSIP-E51A RNG. diff --git a/drivers/entropy/entropy_renesas_ra.c b/drivers/entropy/entropy_renesas_ra.c new file mode 100644 index 00000000000..49f9302722c --- /dev/null +++ b/drivers/entropy/entropy_renesas_ra.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Renesas Electronics Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT renesas_ra_rsip_e51a_trng + +#include +#include + +#include "hw_sce_trng_private.h" +#include "hw_sce_private.h" + +static int entropy_ra_rsip_trng_get_entropy(const struct device *dev, uint8_t *buf, uint16_t len) +{ + ARG_UNUSED(dev); + + if (buf == NULL) { + return -EINVAL; + } + + while (len > 0) { + uint32_t n[4]; + const uint32_t to_copy = MIN(sizeof(n), len); + + if (FSP_SUCCESS != HW_SCE_RNG_Read(n)) { + return -ENODATA; + } + memcpy(buf, n, to_copy); + buf += to_copy; + len -= to_copy; + } + + return 0; +} + +static const struct entropy_driver_api entropy_ra_rsip_trng_api = { + .get_entropy = entropy_ra_rsip_trng_get_entropy, +}; + +static int entropy_ra_rsip_trng_init(const struct device *dev) +{ + HW_SCE_McuSpecificInit(); + return 0; +} + +DEVICE_DT_INST_DEFINE(0, entropy_ra_rsip_trng_init, NULL, NULL, NULL, PRE_KERNEL_1, + CONFIG_ENTROPY_INIT_PRIORITY, &entropy_ra_rsip_trng_api); diff --git a/dts/arm/renesas/ra/ra8/ra8x1.dtsi b/dts/arm/renesas/ra/ra8/ra8x1.dtsi index 6285efac823..925636c85c3 100644 --- a/dts/arm/renesas/ra/ra8/ra8x1.dtsi +++ b/dts/arm/renesas/ra/ra8/ra8x1.dtsi @@ -299,6 +299,10 @@ status = "disabled"; }; + trng: trng { + compatible = "renesas,ra-rsip-e51a-trng"; + }; + option_setting_ofs: option_setting_ofs@300a100 { compatible = "zephyr,memory-region"; reg = <0x0300a100 0x18>; diff --git a/dts/bindings/rng/renesas,ra-rsip-e51a-trng.yaml b/dts/bindings/rng/renesas,ra-rsip-e51a-trng.yaml new file mode 100644 index 00000000000..461ded79cee --- /dev/null +++ b/dts/bindings/rng/renesas,ra-rsip-e51a-trng.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2024 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 + +description: Renesas RA RSIP-E51A TRNG + +compatible: "renesas,ra-rsip-e51a-trng" + +include: base.yaml diff --git a/modules/Kconfig.renesas_fsp b/modules/Kconfig.renesas_fsp index ed7f2acf478..54d9e82452e 100644 --- a/modules/Kconfig.renesas_fsp +++ b/modules/Kconfig.renesas_fsp @@ -32,3 +32,19 @@ config USE_RA_FSP_ADC bool help Enable RA FSP ADC driver + +config USE_RA_FSP_SCE + bool + help + Enable RA FSP SCE driver + +if USE_RA_FSP_SCE + +config HAS_RENESAS_RA_RSIP_E51A + bool + default y + depends on ENTROPY_RENESAS_RA_RSIP_E51A_TRNG + help + Includes RSIP-E51A implementation for SCE driver + +endif