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+
135138typedef 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-
174167static const char * CFGSEP = "," ;
175168
176169static 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+
263271static 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
585597static 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};
0 commit comments