Skip to content

Commit fbe0c39

Browse files
committed
[ot] hw/opentitan: ot_otp: retrieve HW config parameters from buffered data
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent d7583e8 commit fbe0c39

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

hw/opentitan/ot_otp_dj.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,22 +1118,34 @@ ot_otp_dj_update_status_error(OtOTPImplIf *dev, OtOTPStatus error, bool set)
11181118

11191119
static void ot_otp_dj_pwr_load_hw_cfg(OtOTPEngineState *s)
11201120
{
1121-
OtOTPStorage *otp = s->otp;
1121+
OtOTPImplIfClass *ic = OT_OTP_IMPL_IF_GET_CLASS(s);
1122+
1123+
const OtOTPPartDesc *pdesc0 = &ic->part_descs[OTP_PART_HW_CFG0];
1124+
const OtOTPPartDesc *pdesc1 = &ic->part_descs[OTP_PART_HW_CFG1];
1125+
const OtOTPPartController *pctrl0 = &s->part_ctrls[OTP_PART_HW_CFG0];
1126+
const OtOTPPartController *pctrl1 = &s->part_ctrls[OTP_PART_HW_CFG1];
1127+
11221128
OtOTPHWCfg *hw_cfg = s->hw_cfg;
11231129

1124-
memcpy(hw_cfg->device_id, &otp->data[R_HW_CFG0_DEVICE_ID],
1130+
memcpy(hw_cfg->device_id,
1131+
&pctrl0->buffer.data[R_HW_CFG0_DEVICE_ID - pdesc0->offset],
11251132
sizeof(hw_cfg->device_id));
1126-
memcpy(hw_cfg->manuf_state, &otp->data[R_HW_CFG0_MANUF_STATE],
1133+
memcpy(hw_cfg->manuf_state,
1134+
&pctrl0->buffer.data[R_HW_CFG0_MANUF_STATE - pdesc0->offset],
11271135
sizeof(hw_cfg->manuf_state));
1128-
memcpy(hw_cfg->soc_dbg_state, &otp->data[R_HW_CFG1_SOC_DBG_STATE],
1136+
memcpy(hw_cfg->soc_dbg_state,
1137+
&pctrl1->buffer.data[R_HW_CFG1_SOC_DBG_STATE - pdesc1->offset],
11291138
sizeof(hw_cfg->soc_dbg_state));
11301139
/* do not prevent execution from SRAM if no OTP configuration is loaded */
11311140
hw_cfg->en_sram_ifetch_mb8 =
1132-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_SRAM_IFETCH] :
1133-
OT_MULTIBITBOOL8_TRUE;
1141+
s->blk ?
1142+
(uint8_t)
1143+
pctrl1->buffer.data[R_HW_CFG1_EN_SRAM_IFETCH - pdesc1->offset] :
1144+
OT_MULTIBITBOOL8_TRUE;
11341145
/* do not prevent CSRNG app reads if no OTP configuration is loaded */
11351146
hw_cfg->en_csrng_sw_app_read_mb8 =
1136-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_CSRNG_SW_APP_READ] :
1147+
s->blk ? (uint8_t)pctrl1->buffer
1148+
.data[R_HW_CFG1_EN_CSRNG_SW_APP_READ - pdesc1->offset] :
11371149
OT_MULTIBITBOOL8_TRUE;
11381150
}
11391151

hw/opentitan/ot_otp_eg.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,20 +1007,31 @@ ot_otp_eg_update_status_error(OtOTPImplIf *dev, OtOTPStatus error, bool set)
10071007

10081008
static void ot_otp_eg_pwr_load_hw_cfg(OtOTPEngineState *s)
10091009
{
1010-
OtOTPStorage *otp = s->otp;
1010+
OtOTPImplIfClass *ic = OT_OTP_IMPL_IF_GET_CLASS(s);
1011+
1012+
const OtOTPPartDesc *pdesc0 = &ic->part_descs[OTP_PART_HW_CFG0];
1013+
const OtOTPPartDesc *pdesc1 = &ic->part_descs[OTP_PART_HW_CFG1];
1014+
const OtOTPPartController *pctrl0 = &s->part_ctrls[OTP_PART_HW_CFG0];
1015+
const OtOTPPartController *pctrl1 = &s->part_ctrls[OTP_PART_HW_CFG1];
1016+
10111017
OtOTPHWCfg *hw_cfg = s->hw_cfg;
10121018

1013-
memcpy(hw_cfg->device_id, &otp->data[R_HW_CFG0_DEVICE_ID],
1019+
memcpy(hw_cfg->device_id,
1020+
&pctrl0->buffer.data[R_HW_CFG0_DEVICE_ID - pdesc0->offset],
10141021
sizeof(hw_cfg->device_id));
1015-
memcpy(hw_cfg->manuf_state, &otp->data[R_HW_CFG0_MANUF_STATE],
1022+
memcpy(hw_cfg->manuf_state,
1023+
&pctrl0->buffer.data[R_HW_CFG0_MANUF_STATE - pdesc0->offset],
10161024
sizeof(hw_cfg->manuf_state));
10171025
/* do not prevent execution from SRAM if no OTP configuration is loaded */
10181026
hw_cfg->en_sram_ifetch_mb8 =
1019-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_SRAM_IFETCH] :
1020-
OT_MULTIBITBOOL8_TRUE;
1027+
s->blk ?
1028+
(uint8_t)
1029+
pctrl1->buffer.data[R_HW_CFG1_EN_SRAM_IFETCH - pdesc1->offset] :
1030+
OT_MULTIBITBOOL8_TRUE;
10211031
/* do not prevent CSRNG app reads if no OTP configuration is loaded */
10221032
hw_cfg->en_csrng_sw_app_read_mb8 =
1023-
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_CSRNG_SW_APP_READ] :
1033+
s->blk ? (uint8_t)pctrl1->buffer
1034+
.data[R_HW_CFG1_EN_CSRNG_SW_APP_READ - pdesc1->offset] :
10241035
OT_MULTIBITBOOL8_TRUE;
10251036
}
10261037

0 commit comments

Comments
 (0)