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+
136140typedef 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
160165struct OtASTDjClass {
161166 SysBusDeviceClass parent_class ;
162167 ResettablePhases parent_phases ;
163168};
164169
165- /* -------------------------------------------------------------------------- */
166- /* Private implementation */
167- /* -------------------------------------------------------------------------- */
168-
169170static const char * CFGSEP = "," ;
170171
171172static 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+
258274static 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,
456472static 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
579601static 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