[PATCH 0/2] rng: msm: support newer SoCs

Add support for RNG on newer SoCs which shares the RNG hardware between different Execution Environments (EE).
Also enable it by default to fill KASL seed when running Linux.
Signed-off-by: Neil Armstrong neil.armstrong@linaro.org --- Neil Armstrong (2): rng: msm: add support for newer Qualcomm hwrandom IPs configs: qcom_defconfig: enable RNG driver and command
configs/qcom_defconfig | 3 +++ drivers/rng/msm_rng.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) --- base-commit: dc1859f8d2ac3faaa5e2e1d465ec4bd8980520a5 change-id: 20241125-topic-sm8x50-rng-714cd0012391
Best regards,

On recent Qualcomm SoCs, the hardware random generator is initialized and handled by the firmware because shared between different Execution Environments (EE), thus the initialization step should be skipped.
Also support the newer "TRNG" found on SM8550 and newer SoCs that has inbuilt NIST SP800 90B compliant entropic source.
Signed-off-by: Neil Armstrong neil.armstrong@linaro.org --- drivers/rng/msm_rng.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/rng/msm_rng.c b/drivers/rng/msm_rng.c index 658c153d3edb2590b0b470e3067da9aac76169ac..f790d3b60f99bfc04ecd9acdd21405a8c38c257a 100644 --- a/drivers/rng/msm_rng.c +++ b/drivers/rng/msm_rng.c @@ -34,6 +34,7 @@ struct msm_rng_priv { phys_addr_t base; struct clk clk; + bool skip_init; };
static int msm_rng_read(struct udevice *dev, void *data, size_t len) @@ -100,10 +101,15 @@ static int msm_rng_probe(struct udevice *dev)
int ret;
+ priv->skip_init = (bool)dev_get_driver_data(dev); + priv->base = dev_read_addr(dev); if (priv->base == FDT_ADDR_T_NONE) return -EINVAL;
+ if (priv->skip_init) + return 0; + ret = clk_get_by_index(dev, 0, &priv->clk); if (ret) return ret; @@ -119,6 +125,9 @@ static int msm_rng_remove(struct udevice *dev) { struct msm_rng_priv *priv = dev_get_priv(dev);
+ if (priv->skip_init) + return 0; + return msm_rng_enable(priv, 0); }
@@ -127,7 +136,9 @@ static const struct dm_rng_ops msm_rng_ops = { };
static const struct udevice_id msm_rng_match[] = { - { .compatible = "qcom,prng", }, + { .compatible = "qcom,prng", .data = (ulong)false }, + { .compatible = "qcom,prng-ee", .data = (ulong)true }, + { .compatible = "qcom,trng", .data = (ulong)true }, {}, };

25.11.2024 20:12, Neil Armstrong wrote:
On recent Qualcomm SoCs, the hardware random generator is initialized and handled by the firmware because shared between different Execution Environments (EE), thus the initialization step should be skipped.
Also support the newer "TRNG" found on SM8550 and newer SoCs that has inbuilt NIST SP800 90B compliant entropic source.
Signed-off-by: Neil Armstrong neil.armstrong@linaro.org
drivers/rng/msm_rng.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
I've tried this patch on my sdm660 device (which is using qcom,prng-ee) and it seems to work fine. I now see in Linux dmesg:
[ 0.000000] KASLR enabled
Without this patch it was:
[ 0.000000] KASLR disabled due to lack of seed
Tested-by: Alexey Minnekhanov alexeymin@postmarketos.org

Enable the MSM RNG driver by default with the associated command, this will fill KASLR seed when booting Linux.
Signed-off-by: Neil Armstrong neil.armstrong@linaro.org --- configs/qcom_defconfig | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/configs/qcom_defconfig b/configs/qcom_defconfig index ea0dd3e58018c8bf08e4a455a47e29cf1bbd3c60..fa631ea4976a2c38494832b196c60fd127288cc4 100644 --- a/configs/qcom_defconfig +++ b/configs/qcom_defconfig @@ -34,6 +34,7 @@ CONFIG_CMD_UFS=y CONFIG_CMD_USB=y CONFIG_CMD_CAT=y CONFIG_CMD_BMP=y +CONFIG_CMD_RNG=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_LOG=y CONFIG_OF_LIVE=y @@ -96,6 +97,8 @@ CONFIG_PMIC_QCOM=y CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_REGULATOR_QCOM_RPMH=y +CONFIG_DM_RNG=y +CONFIG_RNG_MSM=y CONFIG_SCSI=y CONFIG_MSM_SERIAL=y CONFIG_MSM_GENI_SERIAL=y
participants (2)
-
Alexey Minnekhanov
-
Neil Armstrong