Skip to content

Commit 60d0e9d

Browse files
committed
[ot] hw/opentitan: add a generic API for OTP implementation
This commit is the first step to support platform-specific OTP implementations Signed-off-by: Emmanuel Blot <[email protected]>
1 parent 5ae8cf6 commit 60d0e9d

File tree

13 files changed

+1526
-1425
lines changed

13 files changed

+1526
-1425
lines changed

hw/opentitan/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ config OT_OTBN
4747
config OT_OTP
4848
bool
4949

50+
config OT_OTP_EARLGREY
51+
select OT_OTP
52+
bool
53+
5054
config OT_PINMUX
5155
bool
5256

hw/opentitan/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ softmmu_ss.add(when: 'CONFIG_OT_KMAC', if_true: [files('ot_kmac.c'), libtomcrypt
1919
softmmu_ss.add(when: 'CONFIG_OT_LIFECYCLE', if_true: files('ot_lifecycle.c'))
2020
softmmu_ss.add(when: 'CONFIG_OT_OTBN', if_true: files('ot_otbn.c'))
2121
softmmu_ss.add(when: 'CONFIG_OT_OTP', if_true: files('ot_otp.c'))
22+
softmmu_ss.add(when: 'CONFIG_OT_OTP_EARLGREY', if_true: files('ot_otp_earlgrey.c'))
2223
softmmu_ss.add(when: 'CONFIG_OT_PINMUX', if_true: files('ot_pinmux.c'))
2324
softmmu_ss.add(when: 'CONFIG_OT_PRNG', if_true: files('ot_prng.c'))
2425
softmmu_ss.add(when: 'CONFIG_OT_PWRMGR', if_true: files('ot_pwrmgr.c'))

hw/opentitan/ot_csrng.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,9 @@ static void ot_csrng_regs_write(void *opaque, hwaddr addr, uint64_t val64,
16451645
if (change) {
16461646
xtrace_ot_csrng_info("handling CTRL change", val32);
16471647
ot_csrng_handle_enable(s);
1648-
const OtOTPHWCfg *hw_cfg;
1649-
hw_cfg = ot_otp_ctrl_get_hw_cfg(s->otp_ctrl);
1648+
OtOTPStateClass *oc =
1649+
OBJECT_GET_CLASS(OtOTPStateClass, s->otp_ctrl, TYPE_OT_OTP);
1650+
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(s->otp_ctrl);
16501651
if (hw_cfg->en_csrng_sw_app_read == OT_MULTIBITBOOL8_TRUE) {
16511652
uint32_t sw_app_en = FIELD_EX32(val32, CTRL, SW_APP_ENABLE);
16521653
s->sw_app_granted = sw_app_en == OT_MULTIBITBOOL4_TRUE;

hw/opentitan/ot_entropy_src.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,9 @@ static void ot_entropy_src_reset(DeviceState *dev)
15751575
ibex_irq_set(&s->alerts[ix], 0);
15761576
}
15771577

1578-
const OtOTPHWCfg *hw_cfg;
1579-
hw_cfg = ot_otp_ctrl_get_hw_cfg(s->otp_ctrl);
1578+
OtOTPStateClass *oc =
1579+
OBJECT_GET_CLASS(OtOTPStateClass, s->otp_ctrl, TYPE_OT_OTP);
1580+
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(s->otp_ctrl);
15801581

15811582
s->obs_fifo_en = false;
15821583
s->otp_fw_read = hw_cfg->en_entropy_src_fw_read == OT_MULTIBITBOOL8_TRUE;

hw/opentitan/ot_lifecycle.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ static uint32_t ot_lifecycle_get_lc_state(OtLifeCycleState *s)
249249
uint32_t lc_state;
250250

251251
if (s->otp_ctrl) {
252-
ot_otp_ctrl_get_lc_info(s->otp_ctrl, &lc_state, NULL);
252+
OtOTPStateClass *oc =
253+
OBJECT_GET_CLASS(OtOTPStateClass, s->otp_ctrl, TYPE_OT_OTP);
254+
oc->get_lc_info(s->otp_ctrl, &lc_state, NULL);
253255
} else {
254256
qemu_log_mask(LOG_GUEST_ERROR, "OTP controller not connected\n");
255257
lc_state = LC_STATE_INVALID;
@@ -263,7 +265,9 @@ static uint32_t ot_lifecycle_get_lc_transition_count(OtLifeCycleState *s)
263265
uint32_t lc_tcount;
264266

265267
if (s->otp_ctrl) {
266-
ot_otp_ctrl_get_lc_info(s->otp_ctrl, NULL, &lc_tcount);
268+
OtOTPStateClass *oc =
269+
OBJECT_GET_CLASS(OtOTPStateClass, s->otp_ctrl, TYPE_OT_OTP);
270+
oc->get_lc_info(s->otp_ctrl, NULL, &lc_tcount);
267271
} else {
268272
qemu_log_mask(LOG_GUEST_ERROR, "OTP controller not connected\n");
269273
lc_tcount = LC_TRANSITION_COUNT_MAX + 1u;

0 commit comments

Comments
 (0)