3939#include "qemu/timer.h"
4040#include "qemu/typedefs.h"
4141#include "hw/opentitan/ot_alert.h"
42- #include "hw/opentitan/ot_ast_eg.h"
4342#include "hw/opentitan/ot_common.h"
4443#include "hw/opentitan/ot_entropy_src.h"
4544#include "hw/opentitan/ot_fifo32.h"
45+ #include "hw/opentitan/ot_noise_src.h"
4646#include "hw/opentitan/ot_otp.h"
4747#include "hw/qdev-properties.h"
4848#include "hw/registerfields.h"
@@ -407,11 +407,8 @@ static const char *REG_HI_NAMES[REGS_HI_COUNT] = {
407407 * feed rate to ~0.7 ms max. 128-bit packet can be divided down to 32-bit
408408 * FIFO packets. They are assembled into either 384-bit or 2048-bit packets.
409409 */
410- #define ES_FILL_BITS 128u
411- #define ES_FINAL_FIFO_DEPTH 4u
412- #define ES_FILL_RATE_NS \
413- ((NANOSECONDS_PER_SECOND * ES_FILL_BITS) / \
414- ((uint64_t)OT_AST_EG_RANDOM_4BIT_RATE * 4u))
410+ #define ES_FILL_BITS 128u
411+ #define ES_FINAL_FIFO_DEPTH 4u
415412#define OT_ENTROPY_SRC_FILL_WORD_COUNT (ES_FILL_BITS / (8u * sizeof(uint32_t)))
416413#define ES_WORD_COUNT (OT_ENTROPY_SRC_WORD_COUNT)
417414#define ES_SWREAD_FIFO_WORD_COUNT ES_WORD_COUNT
@@ -483,14 +480,15 @@ struct OtEntropySrcState {
483480 OtFifo32 final_fifo ; /* output FIFO */
484481 hash_state sha3_state ; /* libtomcrypt hash state */
485482 OtEntropySrcFsmState state ;
483+ uint64_t noise_fill_pace_ns ;
486484 unsigned cond_word ; /* count of words processed with SHA3 till hash */
487485 unsigned noise_count ; /* count of consumed noise words since enabled */
488486 unsigned packet_count ; /* count of output packets since enabled */
489487 bool obs_fifo_en ; /* observe FIFO accept incoming data */
490488
491489 char * ot_id ;
492490 unsigned version ; /* emulated version */
493- OtASTEgState * ast ;
491+ DeviceState * noise_src ;
494492 OtOTPState * otp_ctrl ;
495493};
496494
@@ -885,7 +883,7 @@ static void ot_entropy_src_update_filler(OtEntropySrcState *s)
885883 if (!timer_pending (s -> scheduler )) {
886884 trace_ot_entropy_src_info (s -> ot_id , "reschedule" );
887885 uint64_t now = qemu_clock_get_ns (OT_VIRTUAL_CLOCK );
888- timer_mod (s -> scheduler , (int64_t )(now + ( uint64_t ) ES_FILL_RATE_NS ));
886+ timer_mod (s -> scheduler , (int64_t )(now + s -> noise_fill_pace_ns ));
889887 }
890888 }
891889}
@@ -1131,7 +1129,9 @@ static bool ot_entropy_src_fill_noise(OtEntropySrcState *s)
11311129
11321130 uint32_t buffer [OT_ENTROPY_SRC_FILL_WORD_COUNT ];
11331131 /* synchronous read */
1134- ot_ast_eg_getrandom (buffer , sizeof (buffer ));
1132+ OtNoiseSrcIfClass * nsc = OT_NOISE_SRC_IF_GET_CLASS (s -> noise_src );
1133+ OtNoiseSrcIf * nsi = OT_NOISE_SRC_IF (s -> noise_src );
1134+ nsc -> get_noise (nsi , (uint8_t * )buffer , sizeof (buffer ));
11351135
11361136 /* push the whole entropy buffer into the input FIFO */
11371137 unsigned pos = 0 ;
@@ -1801,9 +1801,8 @@ static const MemoryRegionOps ot_entropy_src_hi_ops = {
18011801static Property ot_entropy_src_properties [] = {
18021802 DEFINE_PROP_STRING (OT_COMMON_DEV_ID , OtEntropySrcState , ot_id ),
18031803 DEFINE_PROP_UINT32 ("version" , OtEntropySrcState , version , 0 ),
1804-
1805- DEFINE_PROP_LINK ("ast" , OtEntropySrcState , ast , TYPE_OT_AST_EG ,
1806- OtASTEgState * ),
1804+ DEFINE_PROP_LINK ("noise-src" , OtEntropySrcState , noise_src , TYPE_DEVICE ,
1805+ DeviceState * ),
18071806 DEFINE_PROP_LINK ("otp_ctrl" , OtEntropySrcState , otp_ctrl , TYPE_OT_OTP ,
18081807 OtOTPState * ),
18091808 DEFINE_PROP_END_OF_LIST (),
@@ -1814,7 +1813,7 @@ static void ot_entropy_src_reset_enter(Object *obj, ResetType type)
18141813 OtEntropySrcClass * c = OT_ENTROPY_SRC_GET_CLASS (obj );
18151814 OtEntropySrcState * s = OT_ENTROPY_SRC (obj );
18161815
1817- trace_ot_entropy_src_reset (s -> ot_id );
1816+ trace_ot_entropy_src_reset (s -> ot_id , "enter" );
18181817
18191818 if (c -> parent_phases .enter ) {
18201819 c -> parent_phases .enter (obj , type );
@@ -1879,6 +1878,24 @@ static void ot_entropy_src_reset_enter(Object *obj, ResetType type)
18791878 ot_entropy_src_change_state (s , ENTROPY_SRC_IDLE );
18801879}
18811880
1881+ static void ot_entropy_src_reset_exit (Object * obj , ResetType type )
1882+ {
1883+ OtEntropySrcClass * c = OT_ENTROPY_SRC_GET_CLASS (obj );
1884+ OtEntropySrcState * s = OT_ENTROPY_SRC (obj );
1885+
1886+ trace_ot_entropy_src_reset (s -> ot_id , "exit" );
1887+
1888+ if (c -> parent_phases .enter ) {
1889+ c -> parent_phases .enter (obj , type );
1890+ }
1891+
1892+ OtNoiseSrcIfClass * nsc = OT_NOISE_SRC_IF_GET_CLASS (s -> noise_src );
1893+ OtNoiseSrcIf * nsi = OT_NOISE_SRC_IF (s -> noise_src );
1894+ uint64_t noise_file_rate = nsc -> get_fill_rate (nsi );
1895+ s -> noise_fill_pace_ns =
1896+ (NANOSECONDS_PER_SECOND * ES_FILL_BITS ) / (noise_file_rate * 8ull );
1897+ }
1898+
18821899static void ot_entropy_src_realize (DeviceState * dev , Error * * errp )
18831900{
18841901 (void )errp ;
@@ -1887,8 +1904,10 @@ static void ot_entropy_src_realize(DeviceState *dev, Error **errp)
18871904
18881905 /* emulated version should be specified */
18891906 g_assert (s -> version > 0 );
1890- g_assert (s -> ast );
1907+ g_assert (s -> noise_src );
18911908 g_assert (s -> otp_ctrl );
1909+
1910+ (void )OBJECT_CHECK (OtNoiseSrcIf , s -> noise_src , TYPE_OT_NOISE_SRC_IF );
18921911}
18931912
18941913static void ot_entropy_src_init (Object * obj )
@@ -1949,11 +1968,13 @@ static void ot_entropy_src_class_init(ObjectClass *klass, void *data)
19491968 device_class_set_props (dc , ot_entropy_src_properties );
19501969 set_bit (DEVICE_CATEGORY_MISC , dc -> categories );
19511970
1952- ResettableClass * rc = RESETTABLE_CLASS (klass );
19531971 OtEntropySrcClass * ec = OT_ENTROPY_SRC_CLASS (klass );
19541972 ec -> get_entropy = & ot_entropy_src_get_entropy ;
1973+
1974+ ResettableClass * rc = RESETTABLE_CLASS (klass );
19551975 resettable_class_set_parent_phases (rc , & ot_entropy_src_reset_enter , NULL ,
1956- NULL , & ec -> parent_phases );
1976+ & ot_entropy_src_reset_exit ,
1977+ & ec -> parent_phases );
19571978}
19581979
19591980static const TypeInfo ot_entropy_src_info = {
0 commit comments