Skip to content

Commit 6c12122

Browse files
committed
[ot] hw/opentitan: ot_otp: remove useless entropy API
Move the en_csrng_sw_app_read field to where it belongs: OtOTPHWCfg Signed-off-by: Emmanuel Blot <[email protected]>
1 parent c8ce435 commit 6c12122

File tree

5 files changed

+20
-55
lines changed

5 files changed

+20
-55
lines changed

hw/opentitan/ot_csrng.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,24 +1822,18 @@ static void ot_csrng_regs_write(void *opaque, hwaddr addr, uint64_t val64,
18221822
if (change) {
18231823
xtrace_ot_csrng_info("handling CTRL change", val32);
18241824
ot_csrng_handle_enable(s);
1825-
bool granted;
18261825
OtOTPClass *oc =
18271826
OBJECT_GET_CLASS(OtOTPClass, s->otp_ctrl, TYPE_OT_OTP);
1828-
const OtOTPEntropyCfg *entropy_cfg =
1829-
oc->get_entropy_cfg(s->otp_ctrl);
1830-
if (entropy_cfg) {
1831-
granted =
1832-
entropy_cfg->en_csrng_sw_app_read == OT_MULTIBITBOOL8_TRUE;
1833-
} else {
1834-
/* defaults to granted if no entropy config in OTP */
1835-
granted = true;
1836-
}
1837-
if (granted) {
1827+
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(s->otp_ctrl);
1828+
g_assert(hw_cfg);
1829+
if (hw_cfg->en_csrng_sw_app_read == OT_MULTIBITBOOL8_TRUE) {
18381830
uint32_t sw_app_en = FIELD_EX32(val32, CTRL, SW_APP_ENABLE);
18391831
s->sw_app_granted = sw_app_en == OT_MULTIBITBOOL4_TRUE;
18401832
uint32_t read_int = FIELD_EX32(val32, CTRL, READ_INT_STATE);
18411833
s->read_int_granted = read_int == OT_MULTIBITBOOL4_TRUE;
18421834
} else {
1835+
qemu_log_mask(LOG_GUEST_ERROR, "%s: SW APP disabled in OTP\n",
1836+
__func__);
18431837
s->sw_app_granted = false;
18441838
s->read_int_granted = false;
18451839
}

hw/opentitan/ot_entropy_src.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,10 +1871,6 @@ static void ot_entropy_src_reset_enter(Object *obj, ResetType type)
18711871
ibex_irq_set(&s->alerts[ix], 0);
18721872
}
18731873

1874-
OtOTPClass *oc = OBJECT_GET_CLASS(OtOTPClass, s->otp_ctrl, TYPE_OT_OTP);
1875-
const OtOTPEntropyCfg *entropy_cfg = oc->get_entropy_cfg(s->otp_ctrl);
1876-
g_assert(entropy_cfg);
1877-
18781874
ot_entropy_src_change_state(s, ENTROPY_SRC_IDLE);
18791875
}
18801876

hw/opentitan/ot_otp_dj.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,14 +2926,7 @@ static const OtOTPHWCfg *ot_otp_dj_get_hw_cfg(const OtOTPState *s)
29262926
{
29272927
const OtOTPDjState *ds = OT_OTP_DJ(s);
29282928

2929-
return ds->hw_cfg;
2930-
}
2931-
2932-
static const OtOTPEntropyCfg *ot_otp_dj_get_entropy_cfg(const OtOTPState *s)
2933-
{
2934-
(void)s;
2935-
/* not present Darjeeling OTP */
2936-
return NULL;
2929+
return (const OtOTPHWCfg *)ds->hw_cfg;
29372930
}
29382931

29392932
static void ot_otp_dj_request_entropy_bh(void *opaque)
@@ -3550,6 +3543,10 @@ static void ot_otp_dj_pwr_load_hw_cfg(OtOTPDjState *s)
35503543
hw_cfg->en_sram_ifetch =
35513544
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_SRAM_IFETCH] :
35523545
OT_MULTIBITBOOL8_TRUE;
3546+
/* do not prevent CSRNG app reads if no OTP configuration is loaded */
3547+
hw_cfg->en_csrng_sw_app_read =
3548+
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_CSRNG_SW_APP_READ] :
3549+
OT_MULTIBITBOOL8_TRUE;
35533550
}
35543551

35553552
static void ot_otp_dj_pwr_load_tokens(OtOTPDjState *s)
@@ -3960,7 +3957,7 @@ static void ot_otp_dj_reset_enter(Object *obj, ResetType type)
39603957
*
39613958
* File back-end storage (loading) is processed from
39623959
* the ot_otp_dj_pwr_otp_bh handler, to ensure data is reloaded from the
3963-
* backend on each reset, prior to this very reset fuction. This reset
3960+
* backend on each reset, prior to this very reset function. This reset
39643961
* function should not alter the storage content.
39653962
*
39663963
* Ideally the OTP reset functions should be decoupled from the regular
@@ -3988,6 +3985,7 @@ static void ot_otp_dj_reset_enter(Object *obj, ResetType type)
39883985
s->keygen->edn_sched = false;
39893986

39903987
memset(s->regs, 0, REGS_COUNT * sizeof(uint32_t));
3988+
memset(s->hw_cfg, 0, sizeof(*s->hw_cfg));
39913989

39923990
s->regs[R_DIRECT_ACCESS_REGWEN] = 0x00000001u;
39933991
s->regs[R_CHECK_TRIGGER_REGWEN] = 0x00000001u;
@@ -4070,7 +4068,7 @@ static void ot_otp_dj_realize(DeviceState *dev, Error **errp)
40704068

40714069
/*
40724070
* Set the OTP drive's permissions now during realization. We can't leave it
4073-
* until reset because QEMU might have `-deamonize`d and changed directory,
4071+
* until reset because QEMU might have `-daemonize`d and changed directory,
40744072
* invalidating the filesystem path to the OTP image.
40754073
*/
40764074
if (s->blk) {
@@ -4187,7 +4185,6 @@ static void ot_otp_dj_class_init(ObjectClass *klass, void *data)
41874185

41884186
oc->get_lc_info = &ot_otp_dj_get_lc_info;
41894187
oc->get_hw_cfg = &ot_otp_dj_get_hw_cfg;
4190-
oc->get_entropy_cfg = &ot_otp_dj_get_entropy_cfg;
41914188
oc->get_otp_key = &ot_otp_dj_get_otp_key;
41924189
oc->get_keymgr_secret = &ot_otp_dj_get_keymgr_secret;
41934190
oc->program_req = &ot_otp_dj_program_req;

hw/opentitan/ot_otp_eg.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,6 @@ struct OtOTPEgState {
699699

700700
OtOTPStorage *otp;
701701
OtOTPHWCfg *hw_cfg;
702-
OtOTPEntropyCfg *entropy_cfg;
703702
OtOTPTokens *tokens;
704703
char *hexstr;
705704

@@ -2803,14 +2802,7 @@ static const OtOTPHWCfg *ot_otp_eg_get_hw_cfg(const OtOTPState *s)
28032802
{
28042803
const OtOTPEgState *es = OT_OTP_EG(s);
28052804

2806-
return es->hw_cfg;
2807-
}
2808-
2809-
static const OtOTPEntropyCfg *ot_otp_eg_get_entropy_cfg(const OtOTPState *s)
2810-
{
2811-
const OtOTPEgState *es = OT_OTP_EG(s);
2812-
2813-
return es->entropy_cfg;
2805+
return (const OtOTPHWCfg *)es->hw_cfg;
28142806
}
28152807

28162808
static void ot_otp_eg_request_entropy_bh(void *opaque)
@@ -3425,7 +3417,6 @@ static void ot_otp_eg_pwr_load_hw_cfg(OtOTPEgState *s)
34253417
{
34263418
OtOTPStorage *otp = s->otp;
34273419
OtOTPHWCfg *hw_cfg = s->hw_cfg;
3428-
OtOTPEntropyCfg *entropy_cfg = s->entropy_cfg;
34293420

34303421
memcpy(hw_cfg->device_id, &otp->data[R_HW_CFG0_DEVICE_ID],
34313422
sizeof(hw_cfg->device_id));
@@ -3436,7 +3427,7 @@ static void ot_otp_eg_pwr_load_hw_cfg(OtOTPEgState *s)
34363427
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_SRAM_IFETCH] :
34373428
OT_MULTIBITBOOL8_TRUE;
34383429
/* do not prevent CSRNG app reads if no OTP configuration is loaded */
3439-
entropy_cfg->en_csrng_sw_app_read =
3430+
hw_cfg->en_csrng_sw_app_read =
34403431
s->blk ? (uint8_t)otp->data[R_HW_CFG1_EN_CSRNG_SW_APP_READ] :
34413432
OT_MULTIBITBOOL8_TRUE;
34423433
}
@@ -3944,7 +3935,7 @@ static void ot_otp_eg_reset_enter(Object *obj, ResetType type)
39443935
*
39453936
* File back-end storage (loading) is processed from
39463937
* the ot_otp_eg_pwr_otp_bh handler, to ensure data is reloaded from the
3947-
* backend on each reset, prior to this very reset fuction. This reset
3938+
* backend on each reset, prior to this very reset function. This reset
39483939
* function should not alter the storage content.
39493940
*
39503941
* Ideally the OTP reset functions should be decoupled from the regular
@@ -3972,6 +3963,7 @@ static void ot_otp_eg_reset_enter(Object *obj, ResetType type)
39723963
s->keygen->edn_sched = false;
39733964

39743965
memset(s->regs, 0, REGS_COUNT * sizeof(uint32_t));
3966+
memset(s->hw_cfg, 0, sizeof(*s->hw_cfg));
39753967

39763968
s->regs[R_DIRECT_ACCESS_REGWEN] = 0x1u;
39773969
s->regs[R_CHECK_TRIGGER_REGWEN] = 0x1u;
@@ -4044,7 +4036,7 @@ static void ot_otp_eg_realize(DeviceState *dev, Error **errp)
40444036

40454037
/*
40464038
* Set the OTP drive's permissions now during realization. We can't leave it
4047-
* until reset because QEMU might have `-deamonize`d and changed directory,
4039+
* until reset because QEMU might have `-daemonize`d and changed directory,
40484040
* invalidating the filesystem path to the OTP image.
40494041
*/
40504042
if (s->blk) {
@@ -4104,7 +4096,6 @@ static void ot_otp_eg_init(Object *obj)
41044096
OT_LC_BROADCAST, OT_OTP_LC_BROADCAST_COUNT);
41054097

41064098
s->hw_cfg = g_new0(OtOTPHWCfg, 1u);
4107-
s->entropy_cfg = g_new0(OtOTPEntropyCfg, 1u);
41084099
s->tokens = g_new0(OtOTPTokens, 1u);
41094100
s->regs = g_new0(uint32_t, REGS_COUNT);
41104101
s->dai = g_new0(OtOTPDAIController, 1u);
@@ -4163,7 +4154,6 @@ static void ot_otp_eg_class_init(ObjectClass *klass, void *data)
41634154

41644155
oc->get_lc_info = &ot_otp_eg_get_lc_info;
41654156
oc->get_hw_cfg = &ot_otp_eg_get_hw_cfg;
4166-
oc->get_entropy_cfg = &ot_otp_eg_get_entropy_cfg;
41674157
oc->get_otp_key = &ot_otp_eg_get_otp_key;
41684158
oc->get_keymgr_secret = &ot_otp_eg_get_keymgr_secret;
41694159
oc->program_req = &ot_otp_eg_program_req;

include/hw/opentitan/ot_otp.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef enum {
5757
#define OT_OTP_HWCFG_SOC_DBG_STATE_BYTES 4u
5858

5959
/*
60-
* Hardware configuration (for HW_CFG partition)
60+
* Hardware configuration (for HW_CFG partitions)
6161
*/
6262
typedef struct {
6363
uint8_t device_id[OT_OTP_HWCFG_DEVICE_ID_BYTES];
@@ -66,12 +66,8 @@ typedef struct {
6666
uint8_t soc_dbg_state[OT_OTP_HWCFG_SOC_DBG_STATE_BYTES];
6767
/* the following value is stored as OT_MULTIBITBOOL8 */
6868
uint8_t en_sram_ifetch;
69-
} OtOTPHWCfg;
70-
71-
typedef struct {
72-
/* the following values are stored as OT_MULTIBITBOOL8 */
7369
uint8_t en_csrng_sw_app_read;
74-
} OtOTPEntropyCfg;
70+
} OtOTPHWCfg;
7571

7672
typedef enum {
7773
OTP_TOKEN_TEST_UNLOCK,
@@ -158,14 +154,6 @@ struct OtOTPClass {
158154
*/
159155
const OtOTPHWCfg *(*get_hw_cfg)(const OtOTPState *s);
160156

161-
/*
162-
* Retrieve entropy configuration.
163-
*
164-
* @s the OTP device
165-
* @return the entropy config data (may be NULL if not present in OTP)
166-
*/
167-
const OtOTPEntropyCfg *(*get_entropy_cfg)(const OtOTPState *s);
168-
169157
/*
170158
* Retrieve SRAM scrambling key.
171159
*

0 commit comments

Comments
 (0)