Skip to content

Commit 3b22376

Browse files
Tong Hopm215
authored andcommitted
hw/arm: xlnx-versal-virt: Add AMD/Xilinx TRNG device
Connect 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. Signed-off-by: Tong Ho <tong.ho@amd.com> Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 20231031184611.3029156-3-tong.ho@amd.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
1 parent 9219235 commit 3b22376

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

hw/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ config XLNX_VERSAL
482482
select XLNX_BBRAM
483483
select XLNX_EFUSE_VERSAL
484484
select XLNX_USB_SUBSYS
485+
select XLNX_VERSAL_TRNG
485486

486487
config NPCM7XX
487488
bool

hw/arm/xlnx-versal.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,21 @@ static void versal_create_rtc(Versal *s, qemu_irq *pic)
373373
qdev_get_gpio_in(DEVICE(&s->pmc.apb_irq_orgate), 0));
374374
}
375375

376+
static void versal_create_trng(Versal *s, qemu_irq *pic)
377+
{
378+
SysBusDevice *sbd;
379+
MemoryRegion *mr;
380+
381+
object_initialize_child(OBJECT(s), "trng", &s->pmc.trng,
382+
TYPE_XLNX_VERSAL_TRNG);
383+
sbd = SYS_BUS_DEVICE(&s->pmc.trng);
384+
sysbus_realize(sbd, &error_fatal);
385+
386+
mr = sysbus_mmio_get_region(sbd, 0);
387+
memory_region_add_subregion(&s->mr_ps, MM_PMC_TRNG, mr);
388+
sysbus_connect_irq(sbd, 0, pic[VERSAL_TRNG_IRQ]);
389+
}
390+
376391
static void versal_create_xrams(Versal *s, qemu_irq *pic)
377392
{
378393
int nr_xrams = ARRAY_SIZE(s->lpd.xram.ctrl);
@@ -909,6 +924,7 @@ static void versal_realize(DeviceState *dev, Error **errp)
909924
versal_create_sds(s, pic);
910925
versal_create_pmc_apb_irq_orgate(s, pic);
911926
versal_create_rtc(s, pic);
927+
versal_create_trng(s, pic);
912928
versal_create_xrams(s, pic);
913929
versal_create_bbram(s, pic);
914930
versal_create_efuse(s, pic);

include/hw/arm/xlnx-versal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "hw/dma/xlnx_csu_dma.h"
3131
#include "hw/misc/xlnx-versal-crl.h"
3232
#include "hw/misc/xlnx-versal-pmc-iou-slcr.h"
33+
#include "hw/misc/xlnx-versal-trng.h"
3334
#include "hw/net/xlnx-versal-canfd.h"
3435
#include "hw/misc/xlnx-versal-cfu.h"
3536
#include "hw/misc/xlnx-versal-cframe-reg.h"
@@ -115,6 +116,7 @@ struct Versal {
115116
} iou;
116117

117118
XlnxZynqMPRTC rtc;
119+
XlnxVersalTRng trng;
118120
XlnxBBRam bbram;
119121
XlnxEFuse efuse;
120122
XlnxVersalEFuseCtrl efuse_ctrl;
@@ -159,6 +161,7 @@ struct Versal {
159161
#define VERSAL_OSPI_IRQ 124
160162
#define VERSAL_SD0_IRQ_0 126
161163
#define VERSAL_EFUSE_IRQ 139
164+
#define VERSAL_TRNG_IRQ 141
162165
#define VERSAL_RTC_ALARM_IRQ 142
163166
#define VERSAL_RTC_SECONDS_IRQ 143
164167

@@ -328,4 +331,6 @@ struct Versal {
328331
#define MM_PMC_CRP_SIZE 0x10000
329332
#define MM_PMC_RTC 0xf12a0000
330333
#define MM_PMC_RTC_SIZE 0x10000
334+
#define MM_PMC_TRNG 0xf1230000
335+
#define MM_PMC_TRNG_SIZE 0x10000
331336
#endif

0 commit comments

Comments
 (0)