Skip to content

Commit 01f00f4

Browse files
committed
[ot] hw/opentitan: ot_ast_dj: implement the noise provider interface
Signed-off-by: Emmanuel Blot <[email protected]>
1 parent e5b616a commit 01f00f4

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

hw/opentitan/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config OT_AON_TIMER
1717
config OT_AST_DJ
1818
select IBEX_CLOCK_SRC
1919
select OT_CLOCK_CTRL
20+
select OT_NOISE_SRC
2021
bool
2122

2223
config OT_AST_EG

hw/opentitan/ot_ast_dj.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "hw/opentitan/ot_ast_dj.h"
3838
#include "hw/opentitan/ot_clock_ctrl.h"
3939
#include "hw/opentitan/ot_common.h"
40+
#include "hw/opentitan/ot_noise_src.h"
4041
#include "hw/qdev-properties.h"
4142
#include "hw/registerfields.h"
4243
#include "hw/riscv/ibex_clock_src.h"
@@ -133,6 +134,9 @@ static const char REGB_NAMES[REGSB_COUNT][6U] = {
133134
};
134135
#undef REG_NAME_ENTRY
135136

137+
/* @todo check with HW what is the best default value */
138+
#define OT_AST_DJ_NOISE_BITRATE_DEFAULT 1000000u /* 1 MHz */
139+
136140
typedef struct {
137141
char *name;
138142
unsigned frequency;
@@ -155,17 +159,14 @@ struct OtASTDjState {
155159

156160
char *cfg_topclocks;
157161
char *cfg_aonclocks;
162+
uint32_t noise_bitrate;
158163
};
159164

160165
struct OtASTDjClass {
161166
SysBusDeviceClass parent_class;
162167
ResettablePhases parent_phases;
163168
};
164169

165-
/* -------------------------------------------------------------------------- */
166-
/* Private implementation */
167-
/* -------------------------------------------------------------------------- */
168-
169170
static const char *CFGSEP = ",";
170171

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

259+
static unsigned ot_ast_dj_get_fill_rate(OtNoiseSrcIf *dev)
260+
{
261+
OtASTDjState *s = OT_AST_DJ(dev);
262+
263+
return s->noise_bitrate / 8u; /* bit to byte */
264+
}
265+
266+
static void ot_ast_dj_get_noise(OtNoiseSrcIf *dev, uint8_t *buffer,
267+
size_t length)
268+
{
269+
(void)dev;
270+
271+
qemu_guest_getrandom_nofail((void *)buffer, length);
272+
}
273+
258274
static void ot_ast_dj_parse_clocks(OtASTDjState *s, Error **errp)
259275
{
260276
if (!s->cfg_topclocks) {
@@ -456,6 +472,8 @@ static void ot_ast_dj_regs_write(void *opaque, hwaddr addr, uint64_t val64,
456472
static Property ot_ast_dj_properties[] = {
457473
DEFINE_PROP_STRING("topclocks", OtASTDjState, cfg_topclocks),
458474
DEFINE_PROP_STRING("aonclocks", OtASTDjState, cfg_aonclocks),
475+
DEFINE_PROP_UINT32("noise-bitrate", OtASTDjState, noise_bitrate,
476+
OT_AST_DJ_NOISE_BITRATE_DEFAULT),
459477
DEFINE_PROP_END_OF_LIST(),
460478
};
461479

@@ -574,6 +592,10 @@ static void ot_ast_dj_class_init(ObjectClass *klass, void *data)
574592
OtClockCtrlIfClass *cc = OT_CLOCK_CTRL_IF_CLASS(klass);
575593
cc->clock_enable = &ot_ast_dj_clock_enable;
576594
cc->clock_ext_freq_select = &ot_ast_dj_clock_ext_freq_select;
595+
596+
OtNoiseSrcIfClass *nc = OT_NOISE_SRC_IF_CLASS(klass);
597+
nc->get_fill_rate = &ot_ast_dj_get_fill_rate;
598+
nc->get_noise = &ot_ast_dj_get_noise;
577599
}
578600

579601
static const TypeInfo ot_ast_dj_info = {
@@ -587,6 +609,7 @@ static const TypeInfo ot_ast_dj_info = {
587609
(InterfaceInfo[]){
588610
{ TYPE_IBEX_CLOCK_SRC_IF },
589611
{ TYPE_OT_CLOCK_CTRL_IF },
612+
{ TYPE_OT_NOISE_SRC_IF },
590613
{},
591614
},
592615
};

0 commit comments

Comments
 (0)