Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: smccc: Register smccc_trng platform device

At the moment we probe for the Random Number Generator SMCCC service,
and use that in the core code (arch_get_random). However the hardware
entropy can also be useful to access from userland, and be it to assess
its quality.

Register a platform device when the SMCCC TRNG service is detected, to
allow a hw_random driver to hook onto this.

The function registering the device is deliberately made in a way which
allows expansion, so other services that could be exposed via a platform
device (or some other interface), can be added here easily.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Andre Przywara and committed by
Herbert Xu
b83c2d92 5441a07a

+17
+17
drivers/firmware/smccc/smccc.c
··· 9 9 #include <linux/init.h> 10 10 #include <linux/arm-smccc.h> 11 11 #include <linux/kernel.h> 12 + #include <linux/platform_device.h> 12 13 #include <asm/archrandom.h> 13 14 14 15 static u32 smccc_version = ARM_SMCCC_VERSION_1_0; ··· 43 42 return smccc_version; 44 43 } 45 44 EXPORT_SYMBOL_GPL(arm_smccc_get_version); 45 + 46 + static int __init smccc_devices_init(void) 47 + { 48 + struct platform_device *pdev; 49 + 50 + if (smccc_trng_available) { 51 + pdev = platform_device_register_simple("smccc_trng", -1, 52 + NULL, 0); 53 + if (IS_ERR(pdev)) 54 + pr_err("smccc_trng: could not register device: %ld\n", 55 + PTR_ERR(pdev)); 56 + } 57 + 58 + return 0; 59 + } 60 + device_initcall(smccc_devices_init);