AMD/Xilinx Versal TRNG support
v5 cover AMD/Xilinx Versal TRNG support
This series adds support for the True Random Number Generator (TRNG) in the AMD/Xilinx Versal family of devices.
The series starts by introducing a non-cryptographic grade model of the TRNG controller in the Versal family of devices, followed by instantiating the model in Xilinx Versal machine.
The series ends with a q-test for sanity check of the TRNG model in the Xilinx Versal machine.
V4 => V5
1) Patch #1
Use host-endian uint32 array to seed GRand to ensure consistent sequence generated in different host endian.
2) Patch #3
a) Remove incorrect time-wait for checking status register update by device-under-test.
b) Use g_assert_no_error() instead of g_error() to report failed tests.
c) Rename FAILED macro to TRNG_FAILED to build for Windows.
V3 => V4
1) Patch #1
a) Simplify the data given to g_rand_set_seed_array() as an array of guint32.
b) Use qemu_guest_getrandom_nofail() as the entropy source when the device is configured in TRNG (mode 3).
c) Allow 0 and (2^32-1) as valid output of the generator
d) Add output-related context to VMSTATE.
2) Patch #3
Remove test's assumption of PRNG output != TRNG output.
V2 => V3
1) Patch #1 Use DEFINE_PROP to define a property with custom action on set
2) Patch #1 Remove duplicated version-check on writing to CTRL4 register
3) Patch #2 Defer adding TRNG to machine's device-tree to a future patch
4) Patch #3 Code style fix: group all local vars definitions together
V1 => V2
1) Change patch #1 only
2) Use g_rand_*() PRNG from glib to replace V1's custom PRNG.
3) Implement ResettableClass for device-reset.
4) Add device-mode description to commit-message.
Best regards,
Tong Ho
Tong Ho (3):
hw/misc: Introduce AMD/Xilix Versal TRNG device hw/arm: xlnx-versal-virt: Add AMD/Xilinx TRNG device tests/qtest: Introduce tests for AMD/Xilinx Versal TRNG device
hw/arm/Kconfig | 1 + hw/arm/xlnx-versal.c | 16 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 3 + hw/misc/xlnx-versal-trng.c | 717 ++++++++++++++++++++++++++++ include/hw/arm/xlnx-versal.h | 5 + include/hw/misc/xlnx-versal-trng.h | 58 +++ tests/qtest/meson.build | 2 +- tests/qtest/xlnx-versal-trng-test.c | 485 +++++++++++++++++++ 9 files changed, 1289 insertions(+), 1 deletion(-) create mode 100644 hw/misc/xlnx-versal-trng.c create mode 100644 include/hw/misc/xlnx-versal-trng.h create mode 100644 tests/qtest/xlnx-versal-trng-test.c
Signature · 1 line
2.25.1
PATCH v5 1/3 hw/misc: Introduce AMD/Xilix Versal TRNG device
This adds a non-cryptographic grade implementation of the model for the True Random Number Generator (TRNG) component in AMD/Xilinx Versal device family.
This implements all 3 modes defined by the actual hardware specs, all of which selectable by guest software at will at anytime:
1) PRNG mode, in which the generated sequence is required to be reproducible after reseeded by the same 384-bit value as supplied by guest software.
2) Test mode, in which the generated sequence is required to be reproducible ater reseeded by the same 128-bit test seed supplied by guest software.
3) TRNG mode, in which non-reproducible sequence is generated based on periodic reseed by a suitable entropy source.
This model is only intended for non-real world testing of guest software, where cryptographically strong PRNG or TRNG is not needed.
This model supports versions 1 & 2 of the device, with default to be version 2; the 'hw-version' uint32 property can be set to 0x0100 to override the default.
Other implemented properties:
- 'forced-prng', uint64
When set to non-zero, mode 3's entropy source is implemented as a deterministic sequence based on the given value and other deterministic parameters.
This option allows the emulation to test guest software using mode 3 and to reproduce data-dependent defects.
- 'fips-fault-events', uint32, bit-mask
bit 3: Triggers the SP800-90B entropy health test fault irq bit 1: Triggers the FIPS 140-2 continuous test fault irq
--- hw/misc/Kconfig | 3 + hw/misc/meson.build | 3 + hw/misc/xlnx-versal-trng.c | 717 +++++++++++++++++++++++++++++ include/hw/misc/xlnx-versal-trng.h | 58 +++ 4 files changed, 781 insertions(+) create mode 100644 hw/misc/xlnx-versal-trng.c create mode 100644 include/hw/misc/xlnx-versal-trng.h
hw/misc/Kconfig +3 -0
@@ -197,4 +197,7 @@ config DJMEMC config IOSB bool +config XLNX_VERSAL_TRNG + bool + source macio/Kconfig
hw/misc/meson.build +3 -0
@@ -104,6 +104,9 @@ system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files( 'xlnx-cfi-if.c', 'xlnx-versal-cframe-reg.c', )) +system_ss.add(when: 'CONFIG_XLNX_VERSAL_TRNG', if_true: files( + 'xlnx-versal-trng.c', +)) system_ss.add(when: 'CONFIG_STM32F2XX_SYSCFG', if_true: files('stm32f2xx_syscfg.c')) system_ss.add(when: 'CONFIG_STM32F4XX_SYSCFG', if_true: files('stm32f4xx_syscfg.c')) system_ss.add(when: 'CONFIG_STM32F4XX_EXTI', if_true: files('stm32f4xx_exti.c'))
hw/misc/xlnx-versal-trng.c new file +717 -0
717 lines not on this page · raw message
include/hw/misc/xlnx-versal-trng.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 2/3 hw/arm: xlnx-versal-virt: Add AMD/Xilinx TRNG device
In reply to Tong HoConnect the support for Versal True Random Number Generator (TRNG) device.
Warning: unlike the TRNG component in a real device from the Versal device familiy, the connected TRNG model is not of cryptographic grade and is not intended for use cases when cryptograpically strong TRNG is needed.
--- hw/arm/Kconfig | 1 + hw/arm/xlnx-versal.c | 16 ++++++++++++++++ include/hw/arm/xlnx-versal.h | 5 +++++ 3 files changed, 22 insertions(+)
hw/arm/Kconfig +1 -0
@@ -482,6 +482,7 @@ config XLNX_VERSAL select XLNX_BBRAM select XLNX_EFUSE_VERSAL select XLNX_USB_SUBSYS + select XLNX_VERSAL_TRNG config NPCM7XX bool
hw/arm/xlnx-versal.c +16 -0
@@ -373,6 +373,21 @@ static void versal_create_rtc(Versal *s, qemu_irq *pic) qdev_get_gpio_in(DEVICE(&s->pmc.apb_irq_orgate), 0)); } +static void versal_create_trng (Versal *s,qemu_irq *pic) +{ +SysBusDevice *sbd; +MemoryRegion *mr; + +object_initialize_child (OBJECT (s),"trng" , &s->pmc.trng, +TYPE_XLNX_VERSAL_TRNG ); + sbd =SYS_BUS_DEVICE (&s->pmc.trng); +sysbus_realize (sbd, &error_fatal); + + mr =sysbus_mmio_get_region (sbd,0 ); +memory_region_add_subregion (&s->mr_ps,MM_PMC_TRNG , mr); +sysbus_connect_irq (sbd,0 , pic[VERSAL_TRNG_IRQ ]); +} +static void versal_create_xrams (Versal *s,qemu_irq *pic) {int nr_xrams =ARRAY_SIZE (s->lpd.xram.ctrl);
@@ -909,6 +924,7 @@ static void versal_realize(DeviceState *dev, Error **errp)versal_create_sds (s, pic);versal_create_pmc_apb_irq_orgate (s, pic);versal_create_rtc (s, pic); +versal_create_trng (s, pic);versal_create_xrams (s, pic);versal_create_bbram (s, pic);versal_create_efuse (s, pic);
include/hw/arm/xlnx-versal.h +5 -0
@@ -30,6 +30,7 @@#include "hw/dma/xlnx_csu_dma.h" #include "hw/misc/xlnx-versal-crl.h" #include "hw/misc/xlnx-versal-pmc-iou-slcr.h" +#include "hw/misc/xlnx-versal-trng.h" #include "hw/net/xlnx-versal-canfd.h" #include "hw/misc/xlnx-versal-cfu.h" #include "hw/misc/xlnx-versal-cframe-reg.h"
@@ -115,6 +116,7 @@ struct Versal { } iou;XlnxZynqMPRTC rtc; +XlnxVersalTRng trng;XlnxBBRam bbram;XlnxEFuse efuse;XlnxVersalEFuseCtrl efuse_ctrl;
@@ -159,6 +161,7 @@ struct Versal {#define VERSAL_OSPI_IRQ 124#define VERSAL_SD0_IRQ_0 126#define VERSAL_EFUSE_IRQ 139 +#define VERSAL_TRNG_IRQ 141#define VERSAL_RTC_ALARM_IRQ 142#define VERSAL_RTC_SECONDS_IRQ 143
@@ -328,4 +331,6 @@ struct Versal {#define MM_PMC_CRP_SIZE 0x10000#define MM_PMC_RTC 0xf12a0000#define MM_PMC_RTC_SIZE 0x10000 +#define MM_PMC_TRNG 0xf1230000 +#define MM_PMC_TRNG_SIZE 0x10000#endif
Signature · 1 line
2.25.1
PATCH v5 3/3 tests/qtest: Introduce tests for AMD/Xilinx Versal TRNG device
In reply to Tong Ho--- tests/qtest/meson.build | 2 +- tests/qtest/xlnx-versal-trng-test.c | 485 ++++++++++++++++++++++++++++ 2 files changed, 486 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/xlnx-versal-trng-test.c
tests/qtest/meson.build +1 -1
@@ -216,7 +216,7 @@ qtests_aarch64 = \ (config_all.has_key('CONFIG_TCG') and config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ - (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test'] : []) + \ + (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', 'xlnx-versal-trng-test'] : []) + \ (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : []) + \ (config_all.has_key('CONFIG_TCG') and \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
tests/qtest/xlnx-versal-trng-test.c new file +485 -0
485 lines not on this page · raw message
Signature · 1 line
2.25.1
Peter Maydell
AppliedQuoted 10 lines · Tong Ho
This series adds support for the True Random Number Generator (TRNG) in the AMD/Xilinx Versal family of devices.
The series starts by introducing a non-cryptographic grade model of the TRNG controller in the Versal family of devices, followed by instantiating the model in Xilinx Versal machine.
The series ends with a q-test for sanity check of the TRNG model in the Xilinx Versal machine.
Applied to target-arm.next, thanks.
-- PMM