Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e2f25d6
[ot] hw/opentitan: ot_entropy_src: unify EarlGrey and Darjeeling vers…
rivos-eblot Oct 22, 2025
0002e8c
[ot] hw/opentitan: ot_entropy_src: add support for multiple versions
rivos-eblot Oct 29, 2025
8a1b00e
[ot] hw/opentitan: ot_entropy_src: remove random interface abstraction.
rivos-eblot Oct 23, 2025
f51139b
[ot] hw/opentitan: ot_entropy_src: update FSM
rivos-eblot Oct 29, 2025
f7de31e
[ot] hw/opentitan: ot_csrng: replace ot_random_src_if calls with dire…
rivos-eblot Oct 23, 2025
d0b5b17
[ot] hw/opentitan: ot_noise_src: define a new interface for noise pro…
rivos-eblot Oct 23, 2025
081b593
[ot] hw/opentitan: ot_entropy_src: use the new noise provider interface
rivos-eblot Oct 23, 2025
88ed98e
[ot] hw/opentitan: ot_ast_eg: implement the noise provider interface
rivos-eblot Oct 23, 2025
166eab0
[ot] hw/opentitan: ot_ast_dj: remove ot_random_src interface implemen…
rivos-eblot Oct 23, 2025
98e0dc5
[ot] hw/opentitan: ot_ast_dj: implement the noise provider interface
rivos-eblot Oct 23, 2025
42437b3
[ot] hw/opentitan: ot_random_src: remove ot_random_src implementation
rivos-eblot Oct 23, 2025
63bf2e0
[ot] hw/riscv: ot_darjeeling: update entropy stack configuration
rivos-eblot Oct 23, 2025
dccd8bd
[ot] hw/riscv: ot_earlgrey: update entropy stack configuration
rivos-eblot Oct 23, 2025
87553eb
[ot] hw/opentitan: ot_otp: remove useless entropy API
rivos-eblot Oct 23, 2025
9aec3d9
[ot] hw/opentitan: ot_common: define type aliases for OpenTitan multi…
rivos-eblot Oct 23, 2025
016820d
[ot] hw/opentitan: ot_otp: make multibool bit type more visible
rivos-eblot Oct 23, 2025
a97bfa9
[ot] hw/riscv, hw/opentitan: all: fix dash vs. underscore link names
rivos-eblot Oct 23, 2025
cf90a32
[ot] .gitlab-ci.d/opentitan: ot-smoke.yml: fix typo for Darjeeling sm…
rivos-eblot Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.d/opentitan/ot-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ smoke-tests-ot:
- timeout -s KILL 4 build/qemu-system-riscv32 -M ot-earlgrey,no_epmp_cfg=true -nographic
-object ot-rom_img,id=rom,file=build/exit_eg.bin -d in_asm,int
- timeout -s KILL 4 build/qemu-system-riscv32 -M ot-darjeeling,no_epmp_cfg=true
-object ot-rom_img,id=rom,file=build/exit_eg.bin -d in_asm,int
-object ot-rom_img,id=rom,file=build/exit_dj.bin -d in_asm,int
-nographic -global ot-ibex_wrapper.lc-ignore=on
17 changes: 7 additions & 10 deletions hw/opentitan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ config OT_AON_TIMER

config OT_AST_DJ
select IBEX_CLOCK_SRC
select OT_RANDOM_SRC
select OT_CLOCK_CTRL
select OT_NOISE_SRC
bool

config OT_AST_EG
select IBEX_CLOCK_SRC
select OT_CLOCK_CTRL
select OT_NOISE_SRC
bool

config OT_CLKMGR
Expand Down Expand Up @@ -52,12 +53,8 @@ config OT_DMA
config OT_EDN
bool

config OT_ENTROPY_SRC_EG
select OT_RANDOM_SRC
bool

config OT_ENTROPY_SRC_DJ
select OT_RANDOM_SRC
config OT_ENTROPY_SRC
select OT_NOISE_SRC
bool

config OT_FLASH
Expand Down Expand Up @@ -112,6 +109,9 @@ config OT_MBX
select OT_COMMON
bool

config OT_NOISE_SRC
bool

config OT_OTBN
select OT_KEY_SINK
select OT_BIGNUMBER
Expand Down Expand Up @@ -158,9 +158,6 @@ config OT_PWRMGR
select OT_CLOCK_CTRL
bool

config OT_RANDOM_SRC
bool

config OT_ROM_CTRL
bool
select OT_COMMON
Expand Down
5 changes: 2 additions & 3 deletions hw/opentitan/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ system_ss.add(when: 'CONFIG_OT_DEV_PROXY', if_true: files('ot_dev_proxy.c'))
system_ss.add(when: 'CONFIG_OT_DM_TL', if_true: files('ot_dm_tl.c'))
system_ss.add(when: 'CONFIG_OT_DMA', if_true: [files('ot_dma.c'), libtomcrypt_dep])
system_ss.add(when: 'CONFIG_OT_EDN', if_true: files('ot_edn.c'))
system_ss.add(when: 'CONFIG_OT_ENTROPY_SRC_DJ', if_true: [files('ot_entropy_src_dj.c'), libtomcrypt_dep])
system_ss.add(when: 'CONFIG_OT_ENTROPY_SRC_EG', if_true: [files('ot_entropy_src_eg.c'), libtomcrypt_dep])
system_ss.add(when: 'CONFIG_OT_ENTROPY_SRC', if_true: [files('ot_entropy_src.c'), libtomcrypt_dep])
system_ss.add(when: 'CONFIG_OT_FLASH', if_true: files('ot_flash.c'))
system_ss.add(when: 'CONFIG_OT_GPIO_DJ', if_true: files('ot_gpio_dj.c'))
system_ss.add(when: 'CONFIG_OT_GPIO_EG', if_true: files('ot_gpio_eg.c'))
Expand All @@ -33,6 +32,7 @@ system_ss.add(when: 'CONFIG_OT_KEYMGR_DPE', if_true: files('ot_keymgr_dpe.c'))
system_ss.add(when: 'CONFIG_OT_KMAC', if_true: [files('ot_kmac.c'), libtomcrypt_dep])
system_ss.add(when: 'CONFIG_OT_LC_CTRL', if_true: files('ot_lc_ctrl.c'))
system_ss.add(when: 'CONFIG_OT_MBX', if_true: files('ot_mbx.c'))
system_ss.add(when: 'CONFIG_OT_NOISE_SRC', if_true: files('ot_noise_src.c'))
system_ss.add(when: 'CONFIG_OT_OTBN', if_true: files('ot_otbn.c'))
system_ss.add(when: 'CONFIG_OT_OTP', if_true: files('ot_otp.c'))
system_ss.add(when: 'CONFIG_OT_OTP_BE_IF', if_true: files('ot_otp_be_if.c'))
Expand All @@ -46,7 +46,6 @@ system_ss.add(when: 'CONFIG_OT_PRESENT', if_true: files('ot_present.c'))
system_ss.add(when: 'CONFIG_OT_PRINCE', if_true: files('ot_prince.c'))
system_ss.add(when: 'CONFIG_OT_PRNG', if_true: files('ot_prng.c'))
system_ss.add(when: 'CONFIG_OT_PWRMGR', if_true: files('ot_pwrmgr.c'))
system_ss.add(when: 'CONFIG_OT_RANDOM_SRC', if_true: files('ot_random_src.c'))
system_ss.add(when: 'CONFIG_OT_ROM_CTRL', if_true: files('ot_rom_ctrl.c', 'ot_rom_ctrl_img.c'))
system_ss.add(when: 'CONFIG_OT_RSTMGR', if_true: files('ot_rstmgr.c'))
system_ss.add(when: 'CONFIG_OT_SENSOR_EG', if_true: files('ot_sensor_eg.c'))
Expand Down
101 changes: 26 additions & 75 deletions hw/opentitan/ot_ast_dj.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "hw/opentitan/ot_ast_dj.h"
#include "hw/opentitan/ot_clock_ctrl.h"
#include "hw/opentitan/ot_common.h"
#include "hw/opentitan/ot_random_src.h"
#include "hw/opentitan/ot_noise_src.h"
#include "hw/qdev-properties.h"
#include "hw/registerfields.h"
#include "hw/riscv/ibex_clock_src.h"
Expand Down Expand Up @@ -134,11 +134,8 @@ static const char REGB_NAMES[REGSB_COUNT][6U] = {
};
#undef REG_NAME_ENTRY

typedef struct {
QEMUTimer *timer;
uint64_t *buffer;
bool avail;
} OtASTDjRandom;
/* @todo check with HW what is the best default value */
#define OT_AST_DJ_NOISE_BITRATE_DEFAULT 1000000u /* 1 MHz */

typedef struct {
char *name;
Expand All @@ -154,7 +151,6 @@ struct OtASTDjState {
SysBusDevice parent_obj;

MemoryRegion mmio;
OtASTDjRandom random;

GList *clocks; /* OtASTDjClock */

Expand All @@ -163,63 +159,14 @@ struct OtASTDjState {

char *cfg_topclocks;
char *cfg_aonclocks;
uint32_t noise_bitrate;
};

struct OtASTDjClass {
SysBusDeviceClass parent_class;
ResettablePhases parent_phases;
};

#define OT_AST_DJ_RANDOM_FILL_RATE_NS 1000000ull /* arbitrary: 1 ms */

/* -------------------------------------------------------------------------- */
/* Private implementation */
/* -------------------------------------------------------------------------- */

static int ot_ast_dj_get_random(
OtRandomSrcIf *dev, uint64_t random[OT_RANDOM_SRC_DWORD_COUNT], bool *fips)
{
OtASTDjState *s = OT_AST_DJ(dev);
OtASTDjRandom *rnd = &s->random;

if (!rnd->avail) {
/* not ready */
trace_ot_ast_no_entropy(0);
int wait_ns;
if (timer_pending(s->random.timer)) {
wait_ns = 1;
} else {
/* computed delay fits into a 31-bit value */
wait_ns = (int)(timer_expire_time_ns(s->random.timer) -
qemu_clock_get_ns(OT_VIRTUAL_CLOCK));
}
return wait_ns;
}

memcpy(random, rnd->buffer, OT_RANDOM_SRC_DWORD_COUNT * sizeof(uint64_t));
rnd->avail = false;

/* note: fips compliancy is only simulated here for now */
*fips = true;

uint64_t now = qemu_clock_get_ns(OT_VIRTUAL_CLOCK);
timer_mod(rnd->timer, (int64_t)(now + OT_AST_DJ_RANDOM_FILL_RATE_NS));

return 0;
}

static void ot_ast_dj_random_scheduler(void *opaque)
{
OtASTDjState *s = opaque;
OtASTDjRandom *rnd = &s->random;

qemu_guest_getrandom_nofail(rnd->buffer,
OT_RANDOM_SRC_DWORD_COUNT * sizeof(uint64_t));

rnd->avail = true;
}


static const char *CFGSEP = ",";

static gint ot_ast_dj_match_clock_by_name(gconstpointer a, gconstpointer b)
Expand Down Expand Up @@ -309,6 +256,21 @@ static void ot_ast_dj_clock_ext_freq_select(OtClockCtrlIf *dev, bool enable)
qemu_log_mask(LOG_UNIMP, "%s: not implemented: %u\n", __func__, enable);
}

static unsigned ot_ast_dj_get_fill_rate(OtNoiseSrcIf *dev)
{
OtASTDjState *s = OT_AST_DJ(dev);

return s->noise_bitrate / 8u; /* bit to byte */
}

static void ot_ast_dj_get_noise(OtNoiseSrcIf *dev, uint8_t *buffer,
size_t length)
{
(void)dev;

qemu_guest_getrandom_nofail((void *)buffer, length);
}

static void ot_ast_dj_parse_clocks(OtASTDjState *s, Error **errp)
{
if (!s->cfg_topclocks) {
Expand Down Expand Up @@ -510,6 +472,8 @@ static void ot_ast_dj_regs_write(void *opaque, hwaddr addr, uint64_t val64,
static Property ot_ast_dj_properties[] = {
DEFINE_PROP_STRING("topclocks", OtASTDjState, cfg_topclocks),
DEFINE_PROP_STRING("aonclocks", OtASTDjState, cfg_aonclocks),
DEFINE_PROP_UINT32("noise-bitrate", OtASTDjState, noise_bitrate,
OT_AST_DJ_NOISE_BITRATE_DEFAULT),
DEFINE_PROP_END_OF_LIST(),
};

Expand All @@ -525,16 +489,11 @@ static void ot_ast_dj_reset_enter(Object *obj, ResetType type)
{
OtASTDjClass *c = OT_AST_DJ_GET_CLASS(obj);
OtASTDjState *s = OT_AST_DJ(obj);
OtASTDjRandom *rnd = &s->random;

if (c->parent_phases.enter) {
c->parent_phases.enter(obj, type);
}

timer_del(rnd->timer);
memset(rnd->buffer, 0, OT_RANDOM_SRC_DWORD_COUNT * sizeof(uint64_t));
rnd->avail = false;

memset(s->regsa, 0, REGSA_SIZE);
memset(s->regsb, 0, REGSB_SIZE);

Expand Down Expand Up @@ -584,15 +543,11 @@ static void ot_ast_dj_reset_exit(Object *obj, ResetType type)
{
OtASTDjClass *c = OT_AST_DJ_GET_CLASS(obj);
OtASTDjState *s = OT_AST_DJ(obj);
OtASTDjRandom *rnd = &s->random;

if (c->parent_phases.exit) {
c->parent_phases.exit(obj, type);
}

uint64_t now = qemu_clock_get_ns(OT_VIRTUAL_CLOCK);
timer_mod(rnd->timer, (int64_t)(now + OT_AST_DJ_RANDOM_FILL_RATE_NS));

g_list_foreach(s->clocks, ot_ast_dj_update_clock, s);
}

Expand All @@ -614,11 +569,6 @@ static void ot_ast_dj_init(Object *obj)

s->regsa = g_new0(uint32_t, REGSA_COUNT);
s->regsb = g_new0(uint32_t, REGSB_COUNT);

OtASTDjRandom *rnd = &s->random;

rnd->timer = timer_new_ns(OT_VIRTUAL_CLOCK, &ot_ast_dj_random_scheduler, s);
rnd->buffer = g_new0(uint64_t, OT_RANDOM_SRC_DWORD_COUNT);
}

static void ot_ast_dj_class_init(ObjectClass *klass, void *data)
Expand All @@ -636,15 +586,16 @@ static void ot_ast_dj_class_init(ObjectClass *klass, void *data)
&ot_ast_dj_reset_exit,
&ac->parent_phases);

OtRandomSrcIfClass *rdc = OT_RANDOM_SRC_IF_CLASS(klass);
rdc->get_random_values = &ot_ast_dj_get_random;

IbexClockSrcIfClass *ic = IBEX_CLOCK_SRC_IF_CLASS(klass);
ic->get_clock_source = &ot_ast_dj_get_clock_source;

OtClockCtrlIfClass *cc = OT_CLOCK_CTRL_IF_CLASS(klass);
cc->clock_enable = &ot_ast_dj_clock_enable;
cc->clock_ext_freq_select = &ot_ast_dj_clock_ext_freq_select;

OtNoiseSrcIfClass *nc = OT_NOISE_SRC_IF_CLASS(klass);
nc->get_fill_rate = &ot_ast_dj_get_fill_rate;
nc->get_noise = &ot_ast_dj_get_noise;
}

static const TypeInfo ot_ast_dj_info = {
Expand All @@ -656,9 +607,9 @@ static const TypeInfo ot_ast_dj_info = {
.class_init = &ot_ast_dj_class_init,
.interfaces =
(InterfaceInfo[]){
{ TYPE_OT_RANDOM_SRC_IF },
{ TYPE_IBEX_CLOCK_SRC_IF },
{ TYPE_OT_CLOCK_CTRL_IF },
{ TYPE_OT_NOISE_SRC_IF },
{},
},
};
Expand Down
33 changes: 23 additions & 10 deletions hw/opentitan/ot_ast_eg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "hw/opentitan/ot_ast_eg.h"
#include "hw/opentitan/ot_clock_ctrl.h"
#include "hw/opentitan/ot_common.h"
#include "hw/opentitan/ot_noise_src.h"
#include "hw/qdev-properties.h"
#include "hw/registerfields.h"
#include "hw/riscv/ibex_clock_src.h"
Expand Down Expand Up @@ -132,6 +133,8 @@ static const char REGB_NAMES[REGSB_COUNT][6U] = {
};
#undef REG_NAME_ENTRY

#define OT_AST_EG_NOISE_4BIT_RATE 50000u /* 50 kHz */

typedef struct {
char *name;
unsigned frequency;
Expand Down Expand Up @@ -161,16 +164,6 @@ struct OtASTEgClass {
ResettablePhases parent_phases;
};

/* -------------------------------------------------------------------------- */
/* Public API */
/* -------------------------------------------------------------------------- */

void ot_ast_eg_getrandom(void *buf, size_t len)
{
qemu_guest_getrandom_nofail(buf, len);
}


static const char *CFGSEP = ",";

static gint ot_ast_eg_match_clock_by_name(gconstpointer a, gconstpointer b)
Expand Down Expand Up @@ -260,6 +253,21 @@ static void ot_ast_eg_clock_ext_freq_select(OtClockCtrlIf *dev, bool enable)
qemu_log_mask(LOG_UNIMP, "%s: not implemented: %u\n", __func__, enable);
}

static unsigned ot_ast_eg_get_fill_rate(OtNoiseSrcIf *dev)
{
(void)dev;

return OT_AST_EG_NOISE_4BIT_RATE / 2u; /* 4 bits to byte */
}

static void ot_ast_eg_get_noise(OtNoiseSrcIf *dev, uint8_t *buffer,
size_t length)
{
(void)dev;

qemu_guest_getrandom_nofail((void *)buffer, length);
}

static void ot_ast_eg_parse_clocks(OtASTEgState *s, Error **errp)
{
if (!s->cfg_topclocks) {
Expand Down Expand Up @@ -580,6 +588,10 @@ static void ot_ast_eg_class_init(ObjectClass *klass, void *data)
OtClockCtrlIfClass *cc = OT_CLOCK_CTRL_IF_CLASS(klass);
cc->clock_enable = &ot_ast_eg_clock_enable;
cc->clock_ext_freq_select = &ot_ast_eg_clock_ext_freq_select;

OtNoiseSrcIfClass *nc = OT_NOISE_SRC_IF_CLASS(klass);
nc->get_fill_rate = &ot_ast_eg_get_fill_rate;
nc->get_noise = &ot_ast_eg_get_noise;
}

static const TypeInfo ot_ast_eg_info = {
Expand All @@ -593,6 +605,7 @@ static const TypeInfo ot_ast_eg_info = {
(InterfaceInfo[]){
{ TYPE_IBEX_CLOCK_SRC_IF },
{ TYPE_OT_CLOCK_CTRL_IF },
{ TYPE_OT_NOISE_SRC_IF },
{},
},
};
Expand Down
Loading
Loading