Skip to content

Commit 9468a5d

Browse files
committed
[ot] hw/opentitan: ot_ast_eg: implement the noise provider interface
Signed-off-by: Emmanuel Blot <[email protected]>
1 parent 9bb1bf1 commit 9468a5d

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

hw/opentitan/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config OT_AST_DJ
2323
config OT_AST_EG
2424
select IBEX_CLOCK_SRC
2525
select OT_CLOCK_CTRL
26+
select OT_NOISE_SRC
2627
bool
2728

2829
config OT_CLKMGR

hw/opentitan/ot_ast_eg.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "hw/opentitan/ot_ast_eg.h"
3737
#include "hw/opentitan/ot_clock_ctrl.h"
3838
#include "hw/opentitan/ot_common.h"
39+
#include "hw/opentitan/ot_noise_src.h"
3940
#include "hw/qdev-properties.h"
4041
#include "hw/registerfields.h"
4142
#include "hw/riscv/ibex_clock_src.h"
@@ -132,6 +133,8 @@ static const char REGB_NAMES[REGSB_COUNT][6U] = {
132133
};
133134
#undef REG_NAME_ENTRY
134135

136+
#define OT_AST_EG_NOISE_4BIT_RATE 50000u /* 50 kHz */
137+
135138
typedef struct {
136139
char *name;
137140
unsigned frequency;
@@ -161,16 +164,6 @@ struct OtASTEgClass {
161164
ResettablePhases parent_phases;
162165
};
163166

164-
/* -------------------------------------------------------------------------- */
165-
/* Public API */
166-
/* -------------------------------------------------------------------------- */
167-
168-
void ot_ast_eg_getrandom(void *buf, size_t len)
169-
{
170-
qemu_guest_getrandom_nofail(buf, len);
171-
}
172-
173-
174167
static const char *CFGSEP = ",";
175168

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

256+
static unsigned ot_ast_eg_get_fill_rate(OtNoiseSrcIf *dev)
257+
{
258+
(void)dev;
259+
260+
return OT_AST_EG_NOISE_4BIT_RATE / 2u; /* 4 bits to byte */
261+
}
262+
263+
static void ot_ast_eg_get_noise(OtNoiseSrcIf *dev, uint8_t *buffer,
264+
size_t length)
265+
{
266+
(void)dev;
267+
268+
qemu_guest_getrandom_nofail((void *)buffer, length);
269+
}
270+
263271
static void ot_ast_eg_parse_clocks(OtASTEgState *s, Error **errp)
264272
{
265273
if (!s->cfg_topclocks) {
@@ -580,6 +588,10 @@ static void ot_ast_eg_class_init(ObjectClass *klass, void *data)
580588
OtClockCtrlIfClass *cc = OT_CLOCK_CTRL_IF_CLASS(klass);
581589
cc->clock_enable = &ot_ast_eg_clock_enable;
582590
cc->clock_ext_freq_select = &ot_ast_eg_clock_ext_freq_select;
591+
592+
OtNoiseSrcIfClass *nc = OT_NOISE_SRC_IF_CLASS(klass);
593+
nc->get_fill_rate = &ot_ast_eg_get_fill_rate;
594+
nc->get_noise = &ot_ast_eg_get_noise;
583595
}
584596

585597
static const TypeInfo ot_ast_eg_info = {
@@ -593,6 +605,7 @@ static const TypeInfo ot_ast_eg_info = {
593605
(InterfaceInfo[]){
594606
{ TYPE_IBEX_CLOCK_SRC_IF },
595607
{ TYPE_OT_CLOCK_CTRL_IF },
608+
{ TYPE_OT_NOISE_SRC_IF },
596609
{},
597610
},
598611
};
File renamed without changes.

hw/opentitan/trace-events

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ ot_entropy_src_io_write(const char *id, uint32_t addr, const char * regname, uin
191191
ot_entropy_src_no_entropy(const char *id, unsigned count) "%s: only %u words available"
192192
ot_entropy_src_obs_fifo(const char *id, unsigned level, unsigned thold) "%s: level %u, threshold %u"
193193
ot_entropy_src_push_bypass_entropy(const char *id, unsigned slot) "%s: final FIFO depth: %u"
194-
ot_entropy_src_reset(const char *id, void) "%s: "
194+
ot_entropy_src_reset(const char *id, const char *phase) "%s: %s"
195195
ot_entropy_src_show_buffer(const char *id, const char *func, int line, const char *msg, const char *hexstr) "%s: %s:%u %s: %s"
196196
ot_entropy_src_update_filler(const char *id, bool iok, bool ook, bool pok, bool all) "%s: in %u, out %u, proc %u -> %u"
197197

include/hw/opentitan/ot_ast_eg.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,4 @@
3333
#define TYPE_OT_AST_EG "ot-ast-eg"
3434
OBJECT_DECLARE_TYPE(OtASTEgState, OtASTEgClass, OT_AST_EG)
3535

36-
#define OT_AST_EG_RANDOM_4BIT_RATE 50000u /* 50 kHz */
37-
38-
void ot_ast_eg_getrandom(void *buf, size_t len);
39-
4036
#endif /* HW_OPENTITAN_OT_AST_EG_H */

0 commit comments

Comments
 (0)