|
61 | 61 | #define LCI_PROG_SCHED_NS 1000u /* 1us*/ |
62 | 62 |
|
63 | 63 | /* Use a timer with a small delay instead of a BH for reliability */ |
64 | | -#define DIGEST_DECOUPLE_DELAY_NS 100u /* 100 ns */ |
| 64 | +#define DIGEST_DECOUPLE_DELAY_NS 100u /* 100 ns */ |
| 65 | +#define ENTROPY_RESCHEDULE_DELAY_NS 100u /* 100 ns */ |
65 | 66 |
|
66 | 67 | /* The size of keys used for OTP scrambling */ |
67 | 68 | #define OTP_SCRAMBLING_KEY_WIDTH 128u |
@@ -206,7 +207,7 @@ struct OtOTPScrmblKeyInit_ { |
206 | 207 | }; |
207 | 208 |
|
208 | 209 | struct OtOTPKeyGen_ { |
209 | | - QEMUBH *entropy_bh; |
| 210 | + QEMUTimer *request_entropy; |
210 | 211 | OtPresentState *present; |
211 | 212 | OtPrngState *prng; |
212 | 213 | OtFifo32 entropy_buf; |
@@ -1648,7 +1649,7 @@ static const OtOTPHWCfg *ot_otp_engine_get_hw_cfg(const OtOTPIf *dev) |
1648 | 1649 | return (const OtOTPHWCfg *)s->hw_cfg; |
1649 | 1650 | } |
1650 | 1651 |
|
1651 | | -static void ot_otp_engine_request_entropy_bh(void *opaque) |
| 1652 | +static void ot_otp_engine_request_entropy(void *opaque) |
1652 | 1653 | { |
1653 | 1654 | OtOTPEngineState *s = opaque; |
1654 | 1655 |
|
@@ -1683,7 +1684,9 @@ ot_otp_engine_keygen_push_entropy(void *opaque, uint32_t bits, bool fips) |
1683 | 1684 | resched); |
1684 | 1685 |
|
1685 | 1686 | if (resched && !s->keygen->edn_sched) { |
1686 | | - qemu_bh_schedule(s->keygen->entropy_bh); |
| 1687 | + int64_t now = qemu_clock_get_ns(OT_OTP_HW_CLOCK); |
| 1688 | + timer_mod(s->keygen->request_entropy, |
| 1689 | + now + ENTROPY_RESCHEDULE_DELAY_NS); |
1687 | 1690 | } |
1688 | 1691 | } |
1689 | 1692 |
|
@@ -1817,7 +1820,9 @@ static void ot_otp_engine_generate_scrambling_key( |
1817 | 1820 |
|
1818 | 1821 | if (needed_entropy) { |
1819 | 1822 | /* some entropy bits have been used, refill the buffer */ |
1820 | | - qemu_bh_schedule(s->keygen->entropy_bh); |
| 1823 | + int64_t now = qemu_clock_get_ns(OT_OTP_HW_CLOCK); |
| 1824 | + timer_mod(s->keygen->request_entropy, |
| 1825 | + now + ENTROPY_RESCHEDULE_DELAY_NS); |
1821 | 1826 | } |
1822 | 1827 | } |
1823 | 1828 |
|
@@ -2756,7 +2761,7 @@ static void ot_otp_engine_reset_enter(Object *obj, ResetType type) |
2756 | 2761 | timer_del(s->dai->delay); |
2757 | 2762 | timer_del(s->dai->digest_write); |
2758 | 2763 | timer_del(s->lci->prog_delay); |
2759 | | - qemu_bh_cancel(s->keygen->entropy_bh); |
| 2764 | + timer_del(s->keygen->request_entropy); |
2760 | 2765 | s->keygen->edn_sched = false; |
2761 | 2766 |
|
2762 | 2767 | memset(s->hw_cfg, 0, sizeof(*s->hw_cfg)); |
@@ -2815,7 +2820,8 @@ static void ot_otp_engine_reset_exit(Object *obj, ResetType type) |
2815 | 2820 | ot_edn_connect_endpoint(s->edn, s->edn_ep, |
2816 | 2821 | &ot_otp_engine_keygen_push_entropy, s); |
2817 | 2822 |
|
2818 | | - qemu_bh_schedule(s->keygen->entropy_bh); |
| 2823 | + int64_t now = qemu_clock_get_ns(OT_OTP_HW_CLOCK); |
| 2824 | + timer_mod(s->keygen->request_entropy, now + ENTROPY_RESCHEDULE_DELAY_NS); |
2819 | 2825 | } |
2820 | 2826 |
|
2821 | 2827 | static void ot_otp_engine_realize(DeviceState *dev, Error **errp) |
@@ -2908,9 +2914,10 @@ static void ot_otp_engine_init(Object *obj) |
2908 | 2914 | timer_new_ns(OT_VIRTUAL_CLOCK, &ot_otp_engine_dai_write_digest, s); |
2909 | 2915 | s->lci->prog_delay = |
2910 | 2916 | timer_new_ns(OT_OTP_HW_CLOCK, &ot_otp_engine_lci_write_word, s); |
| 2917 | + s->keygen->request_entropy = |
| 2918 | + timer_new_ns(OT_OTP_HW_CLOCK, &ot_otp_engine_request_entropy, s); |
2911 | 2919 | s->pwr_otp_bh = qemu_bh_new(&ot_otp_engine_pwr_otp_bh, s); |
2912 | 2920 | s->lc_broadcast.bh = qemu_bh_new(&ot_otp_engine_lc_broadcast_bh, s); |
2913 | | - s->keygen->entropy_bh = qemu_bh_new(&ot_otp_engine_request_entropy_bh, s); |
2914 | 2921 |
|
2915 | 2922 | for (unsigned part_ix = 0; part_ix < s->part_count; part_ix++) { |
2916 | 2923 | if (!s->part_descs[part_ix].buffered) { |
|
0 commit comments