arm64: Add support for SMCCC TRNG entropy source
authorAndre Przywara <andre.przywara@arm.com>
Wed, 6 Jan 2021 10:34:52 +0000 (10:34 +0000)
committerWill Deacon <will@kernel.org>
Thu, 21 Jan 2021 17:42:46 +0000 (17:42 +0000)
commit38db987316a38a3fe55ff7f5f4653fcb520a9d26
tree030b00547ab656b0e3d9ec8fd502ce5b0c566e80
parenta37e31fc97efe7f7c68cb381cf4390e472c09061
arm64: Add support for SMCCC TRNG entropy source

The ARM architected TRNG firmware interface, described in ARM spec
DEN0098, defines an ARM SMCCC based interface to a true random number
generator, provided by firmware.
This can be discovered via the SMCCC >=v1.1 interface, and provides
up to 192 bits of entropy per call.

Hook this SMC call into arm64's arch_get_random_*() implementation,
coming to the rescue when the CPU does not implement the ARM v8.5 RNG
system registers.

For the detection, we piggy back on the PSCI/SMCCC discovery (which gives
us the conduit to use (hvc/smc)), then try to call the
ARM_SMCCC_TRNG_VERSION function, which returns -1 if this interface is
not implemented.

Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/archrandom.h