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_random_src.h"
4140#include "hw/qdev-properties.h"
4241#include "hw/registerfields.h"
4342#include "hw/riscv/ibex_clock_src.h"
@@ -134,12 +133,6 @@ static const char REGB_NAMES[REGSB_COUNT][6U] = {
134133};
135134#undef REG_NAME_ENTRY
136135
137- typedef struct {
138- QEMUTimer * timer ;
139- uint64_t * buffer ;
140- bool avail ;
141- } OtASTDjRandom ;
142-
143136typedef struct {
144137 char * name ;
145138 unsigned frequency ;
@@ -154,7 +147,6 @@ struct OtASTDjState {
154147 SysBusDevice parent_obj ;
155148
156149 MemoryRegion mmio ;
157- OtASTDjRandom random ;
158150
159151 GList * clocks ; /* OtASTDjClock */
160152
@@ -170,56 +162,10 @@ struct OtASTDjClass {
170162 ResettablePhases parent_phases ;
171163};
172164
173- #define OT_AST_DJ_RANDOM_FILL_RATE_NS 1000000ull /* arbitrary: 1 ms */
174-
175165/* -------------------------------------------------------------------------- */
176166/* Private implementation */
177167/* -------------------------------------------------------------------------- */
178168
179- static int ot_ast_dj_get_random (
180- OtRandomSrcIf * dev , uint64_t random [OT_RANDOM_SRC_DWORD_COUNT ], bool * fips )
181- {
182- OtASTDjState * s = OT_AST_DJ (dev );
183- OtASTDjRandom * rnd = & s -> random ;
184-
185- if (!rnd -> avail ) {
186- /* not ready */
187- trace_ot_ast_no_entropy (0 );
188- int wait_ns ;
189- if (timer_pending (s -> random .timer )) {
190- wait_ns = 1 ;
191- } else {
192- /* computed delay fits into a 31-bit value */
193- wait_ns = (int )(timer_expire_time_ns (s -> random .timer ) -
194- qemu_clock_get_ns (OT_VIRTUAL_CLOCK ));
195- }
196- return wait_ns ;
197- }
198-
199- memcpy (random , rnd -> buffer , OT_RANDOM_SRC_DWORD_COUNT * sizeof (uint64_t ));
200- rnd -> avail = false;
201-
202- /* note: fips compliancy is only simulated here for now */
203- * fips = true;
204-
205- uint64_t now = qemu_clock_get_ns (OT_VIRTUAL_CLOCK );
206- timer_mod (rnd -> timer , (int64_t )(now + OT_AST_DJ_RANDOM_FILL_RATE_NS ));
207-
208- return 0 ;
209- }
210-
211- static void ot_ast_dj_random_scheduler (void * opaque )
212- {
213- OtASTDjState * s = opaque ;
214- OtASTDjRandom * rnd = & s -> random ;
215-
216- qemu_guest_getrandom_nofail (rnd -> buffer ,
217- OT_RANDOM_SRC_DWORD_COUNT * sizeof (uint64_t ));
218-
219- rnd -> avail = true;
220- }
221-
222-
223169static const char * CFGSEP = "," ;
224170
225171static gint ot_ast_dj_match_clock_by_name (gconstpointer a , gconstpointer b )
@@ -525,16 +471,11 @@ static void ot_ast_dj_reset_enter(Object *obj, ResetType type)
525471{
526472 OtASTDjClass * c = OT_AST_DJ_GET_CLASS (obj );
527473 OtASTDjState * s = OT_AST_DJ (obj );
528- OtASTDjRandom * rnd = & s -> random ;
529474
530475 if (c -> parent_phases .enter ) {
531476 c -> parent_phases .enter (obj , type );
532477 }
533478
534- timer_del (rnd -> timer );
535- memset (rnd -> buffer , 0 , OT_RANDOM_SRC_DWORD_COUNT * sizeof (uint64_t ));
536- rnd -> avail = false;
537-
538479 memset (s -> regsa , 0 , REGSA_SIZE );
539480 memset (s -> regsb , 0 , REGSB_SIZE );
540481
@@ -584,15 +525,11 @@ static void ot_ast_dj_reset_exit(Object *obj, ResetType type)
584525{
585526 OtASTDjClass * c = OT_AST_DJ_GET_CLASS (obj );
586527 OtASTDjState * s = OT_AST_DJ (obj );
587- OtASTDjRandom * rnd = & s -> random ;
588528
589529 if (c -> parent_phases .exit ) {
590530 c -> parent_phases .exit (obj , type );
591531 }
592532
593- uint64_t now = qemu_clock_get_ns (OT_VIRTUAL_CLOCK );
594- timer_mod (rnd -> timer , (int64_t )(now + OT_AST_DJ_RANDOM_FILL_RATE_NS ));
595-
596533 g_list_foreach (s -> clocks , ot_ast_dj_update_clock , s );
597534}
598535
@@ -614,11 +551,6 @@ static void ot_ast_dj_init(Object *obj)
614551
615552 s -> regsa = g_new0 (uint32_t , REGSA_COUNT );
616553 s -> regsb = g_new0 (uint32_t , REGSB_COUNT );
617-
618- OtASTDjRandom * rnd = & s -> random ;
619-
620- rnd -> timer = timer_new_ns (OT_VIRTUAL_CLOCK , & ot_ast_dj_random_scheduler , s );
621- rnd -> buffer = g_new0 (uint64_t , OT_RANDOM_SRC_DWORD_COUNT );
622554}
623555
624556static void ot_ast_dj_class_init (ObjectClass * klass , void * data )
@@ -636,9 +568,6 @@ static void ot_ast_dj_class_init(ObjectClass *klass, void *data)
636568 & ot_ast_dj_reset_exit ,
637569 & ac -> parent_phases );
638570
639- OtRandomSrcIfClass * rdc = OT_RANDOM_SRC_IF_CLASS (klass );
640- rdc -> get_random_values = & ot_ast_dj_get_random ;
641-
642571 IbexClockSrcIfClass * ic = IBEX_CLOCK_SRC_IF_CLASS (klass );
643572 ic -> get_clock_source = & ot_ast_dj_get_clock_source ;
644573
@@ -656,7 +585,6 @@ static const TypeInfo ot_ast_dj_info = {
656585 .class_init = & ot_ast_dj_class_init ,
657586 .interfaces =
658587 (InterfaceInfo []){
659- { TYPE_OT_RANDOM_SRC_IF },
660588 { TYPE_IBEX_CLOCK_SRC_IF },
661589 { TYPE_OT_CLOCK_CTRL_IF },
662590 {},
0 commit comments