Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions hw/opentitan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ config OT_EDN

config OT_ENTROPY_SRC
select OT_NOISE_SRC
select OT_OTP_IF
bool

config OT_FLASH
Expand Down Expand Up @@ -89,6 +90,7 @@ config OT_KEY_SINK
config OT_KEYMGR
select OT_KEY_SINK
select OT_LC_CTRL
select OT_OTP_IF
select OT_ROM_CTRL
bool

Expand All @@ -103,6 +105,7 @@ config OT_KMAC
bool

config OT_LC_CTRL
select OT_OTP_IF
bool

config OT_MBX
Expand All @@ -117,23 +120,25 @@ config OT_OTBN
select OT_BIGNUMBER
bool

config OT_OTP
select OT_OTP_BE_IF

config OT_OTP_BE_IF
bool

config OT_OTP_DJ
select OT_OTP
select OT_OTP_IF
select OT_PRESENT
bool

config OT_OTP_EG
select OT_OTP
select OT_OTP_IF
select OT_PRESENT
bool

config OT_OTP_IF
bool

config OT_OTP_OT_BE
select OT_OTP_BE_IF
select OT_OTP_IF
bool

config OT_PINMUX_DJ
Expand Down Expand Up @@ -184,6 +189,7 @@ config OT_SPI_HOST

config OT_SRAM_CTRL
select OT_PRESENT
select OT_OTP_IF
bool

config OT_TIMER
Expand Down
2 changes: 1 addition & 1 deletion hw/opentitan/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ system_ss.add(when: 'CONFIG_OT_LC_CTRL', if_true: files('ot_lc_ctrl.c'))
system_ss.add(when: 'CONFIG_OT_MBX', if_true: files('ot_mbx.c'))
system_ss.add(when: 'CONFIG_OT_NOISE_SRC', if_true: files('ot_noise_src.c'))
system_ss.add(when: 'CONFIG_OT_OTBN', if_true: files('ot_otbn.c'))
system_ss.add(when: 'CONFIG_OT_OTP', if_true: files('ot_otp.c'))
system_ss.add(when: 'CONFIG_OT_OTP_BE_IF', if_true: files('ot_otp_be_if.c'))
system_ss.add(when: 'CONFIG_OT_OTP_DJ', if_true: files('ot_otp_dj.c'))
system_ss.add(when: 'CONFIG_OT_OTP_EG', if_true: files('ot_otp_eg.c'))
system_ss.add(when: 'CONFIG_OT_OTP_IF', if_true: files('ot_otp_if.c'))
system_ss.add(when: 'CONFIG_OT_OTP_OT_BE', if_true: files('ot_otp_ot_be.c'))
system_ss.add(when: 'CONFIG_OT_PINMUX_EG', if_true: files('ot_pinmux_eg.c'))
system_ss.add(when: 'CONFIG_OT_PINMUX_DJ', if_true: files('ot_pinmux_dj.c'))
Expand Down
17 changes: 10 additions & 7 deletions hw/opentitan/ot_csrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "hw/opentitan/ot_csrng.h"
#include "hw/opentitan/ot_entropy_src.h"
#include "hw/opentitan/ot_fifo32.h"
#include "hw/opentitan/ot_otp.h"
#include "hw/opentitan/ot_otp_if.h"
#include "hw/qdev-properties.h"
#include "hw/registerfields.h"
#include "hw/riscv/ibex_common.h"
Expand Down Expand Up @@ -353,7 +353,7 @@ struct OtCSRNGState {
OtCSRNGQueue cmd_requests;

OtEntropySrcState *entropy_src;
OtOTPState *otp_ctrl;
DeviceState *otp_ctrl;
};

/* clang-format off */
Expand Down Expand Up @@ -1822,9 +1822,10 @@ static void ot_csrng_regs_write(void *opaque, hwaddr addr, uint64_t val64,
if (change) {
xtrace_ot_csrng_info("handling CTRL change", val32);
ot_csrng_handle_enable(s);
OtOTPClass *oc =
OBJECT_GET_CLASS(OtOTPClass, s->otp_ctrl, TYPE_OT_OTP);
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(s->otp_ctrl);

OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(oi);
g_assert(hw_cfg);
if (hw_cfg->en_csrng_sw_app_read_mb8 == OT_MULTIBITBOOL8_TRUE) {
uint32_t sw_app_en = FIELD_EX32(val32, CTRL, SW_APP_ENABLE);
Expand Down Expand Up @@ -1938,8 +1939,8 @@ static void ot_csrng_regs_write(void *opaque, hwaddr addr, uint64_t val64,
static Property ot_csrng_properties[] = {
DEFINE_PROP_LINK("entropy-src", OtCSRNGState, entropy_src,
TYPE_OT_ENTROPY_SRC, OtEntropySrcState *),
DEFINE_PROP_LINK("otp-ctrl", OtCSRNGState, otp_ctrl, TYPE_OT_OTP,
OtOTPState *),
DEFINE_PROP_LINK("otp-ctrl", OtCSRNGState, otp_ctrl, TYPE_OT_OTP_IF,
DeviceState *),
DEFINE_PROP_END_OF_LIST(),
};

Expand Down Expand Up @@ -2013,6 +2014,8 @@ static void ot_csrng_realize(DeviceState *dev, Error **errp)

g_assert(s->entropy_src);
g_assert(s->otp_ctrl);

(void)OBJECT_CHECK(OtOTPIf, s->otp_ctrl, TYPE_OT_OTP_IF);
}

static void ot_csrng_init(Object *obj)
Expand Down
7 changes: 1 addition & 6 deletions hw/opentitan/ot_entropy_src.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* QEMU OpenTitan Earlgrey 1.0.0 Entropy Source device
* QEMU OpenTitan Earlgrey Entropy Source device
*
* Copyright (c) 2023-2025 Rivos, Inc.
* Copyright (c) 2025 lowRISC contributors.
Expand Down Expand Up @@ -43,7 +43,6 @@
#include "hw/opentitan/ot_entropy_src.h"
#include "hw/opentitan/ot_fifo32.h"
#include "hw/opentitan/ot_noise_src.h"
#include "hw/opentitan/ot_otp.h"
#include "hw/qdev-properties.h"
#include "hw/registerfields.h"
#include "hw/riscv/ibex_common.h"
Expand Down Expand Up @@ -489,7 +488,6 @@ struct OtEntropySrcState {
char *ot_id;
unsigned version; /* emulated version */
DeviceState *noise_src;
OtOTPState *otp_ctrl;
};

static const uint16_t OtEDNFsmStateCode[] = {
Expand Down Expand Up @@ -1803,8 +1801,6 @@ static Property ot_entropy_src_properties[] = {
DEFINE_PROP_UINT32("version", OtEntropySrcState, version, 0),
DEFINE_PROP_LINK("noise-src", OtEntropySrcState, noise_src, TYPE_DEVICE,
DeviceState *),
DEFINE_PROP_LINK("otp-ctrl", OtEntropySrcState, otp_ctrl, TYPE_OT_OTP,
OtOTPState *),
DEFINE_PROP_END_OF_LIST(),
};

Expand Down Expand Up @@ -1901,7 +1897,6 @@ static void ot_entropy_src_realize(DeviceState *dev, Error **errp)
/* emulated version should be specified */
g_assert(s->version > 0);
g_assert(s->noise_src);
g_assert(s->otp_ctrl);

(void)OBJECT_CHECK(OtNoiseSrcIf, s->noise_src, TYPE_OT_NOISE_SRC_IF);
}
Expand Down
27 changes: 15 additions & 12 deletions hw/opentitan/ot_keymgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "hw/opentitan/ot_kmac.h"
#include "hw/opentitan/ot_lc_ctrl.h"
#include "hw/opentitan/ot_otbn.h"
#include "hw/opentitan/ot_otp.h"
#include "hw/opentitan/ot_otp_if.h"
#include "hw/opentitan/ot_prng.h"
#include "hw/opentitan/ot_rom_ctrl.h"
#include "hw/qdev-properties.h"
Expand Down Expand Up @@ -452,7 +452,7 @@ typedef struct OtKeyMgrState {
uint8_t kmac_app;
OtFlashState *flash_ctrl;
OtLcCtrlState *lc_ctrl;
OtOTPState *otp_ctrl;
DeviceState *otp_ctrl;
OtRomCtrlState *rom_ctrl;
DeviceState *key_sinks[KEYMGR_KEY_SINK_COUNT];
char *seed_xstrs[KEYMGR_SEED_COUNT];
Expand Down Expand Up @@ -1068,8 +1068,9 @@ static size_t ot_keymgr_kdf_append_km_div(OtKeyMgrState *s)

static size_t ot_keymgr_kdf_append_dev_id(OtKeyMgrState *s)
{
OtOTPClass *otp_oc = OBJECT_GET_CLASS(OtOTPClass, s->otp_ctrl, TYPE_OT_OTP);
const OtOTPHWCfg *hw_cfg = otp_oc->get_hw_cfg(s->otp_ctrl);
OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(oi);

ot_keymgr_kdf_push_bytes(s, hw_cfg->device_id,
OT_OTP_HWCFG_DEVICE_ID_BYTES);
Expand Down Expand Up @@ -1193,12 +1194,12 @@ static size_t ot_keymgr_kdf_append_key_version(OtKeyMgrState *s)
static void ot_keymgr_get_root_key(OtKeyMgrState *s, OtOTPKeyMgrSecret *share0,
OtOTPKeyMgrSecret *share1)
{
OtOTPClass *oc = OBJECT_GET_CLASS(OtOTPClass, s->otp_ctrl, TYPE_OT_OTP);
g_assert(oc);
oc->get_keymgr_secret(s->otp_ctrl,
OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0, share0);
oc->get_keymgr_secret(s->otp_ctrl,
OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1, share1);
OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
oc->get_keymgr_secret(oi, OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0,
share0);
oc->get_keymgr_secret(oi, OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1,
share1);

if (trace_event_get_state(TRACE_OT_KEYMGR_DUMP_CREATOR_ROOT_KEY)) {
trace_ot_keymgr_dump_creator_root_key(
Expand Down Expand Up @@ -2332,8 +2333,8 @@ static Property ot_keymgr_properties[] = {
DEFINE_PROP_UINT8("kmac-app", OtKeyMgrState, kmac_app, UINT8_MAX),
DEFINE_PROP_LINK("lc-ctrl", OtKeyMgrState, lc_ctrl, TYPE_OT_LC_CTRL,
OtLcCtrlState *),
DEFINE_PROP_LINK("otp-ctrl", OtKeyMgrState, otp_ctrl, TYPE_OT_OTP,
OtOTPState *),
DEFINE_PROP_LINK("otp-ctrl", OtKeyMgrState, otp_ctrl, TYPE_OT_OTP_IF,
DeviceState *),
DEFINE_PROP_LINK("rom_ctrl", OtKeyMgrState, rom_ctrl, TYPE_OT_ROM_CTRL,
OtRomCtrlState *),
DEFINE_PROP_LINK("aes", OtKeyMgrState, key_sinks[KEYMGR_KEY_SINK_AES],
Expand Down Expand Up @@ -2399,6 +2400,8 @@ static void ot_keymgr_reset_enter(Object *obj, ResetType type)
g_assert(s->otp_ctrl);
g_assert(s->rom_ctrl);

(void)OBJECT_CHECK(OtOTPIf, s->otp_ctrl, TYPE_OT_OTP_IF);

/* reset registers */
memset(s->regs, 0u, sizeof(s->regs));
s->regs[R_CFG_REGWEN] = 0x1u;
Expand Down
36 changes: 20 additions & 16 deletions hw/opentitan/ot_keymgr_dpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "hw/opentitan/ot_kmac.h"
#include "hw/opentitan/ot_lc_ctrl.h"
#include "hw/opentitan/ot_otbn.h"
#include "hw/opentitan/ot_otp.h"
#include "hw/opentitan/ot_otp_if.h"
#include "hw/opentitan/ot_prng.h"
#include "hw/opentitan/ot_rom_ctrl.h"
#include "hw/qdev-properties.h"
Expand Down Expand Up @@ -410,7 +410,7 @@ typedef struct OtKeyMgrDpeState {
OtKMACState *kmac;
uint8_t kmac_app;
OtLcCtrlState *lc_ctrl;
OtOTPState *otp;
DeviceState *otp_ctrl;
OtRomCtrlState *rom_ctrl[NUM_ROM_DIGEST_INPUTS];
DeviceState *key_sinks[KEYMGR_DPE_KEY_SINK_COUNT];
char *seed_xstrs[KEYMGR_DPE_SEED_COUNT];
Expand Down Expand Up @@ -1027,9 +1027,9 @@ ot_keymgr_dpe_kdf_append_creator_seed(OtKeyMgrDpeState *s, bool *dvalid)
{
OtOTPKeyMgrSecret secret = { 0u };

OtOTPClass *otp_oc = OBJECT_GET_CLASS(OtOTPClass, s->otp, TYPE_OT_OTP);
g_assert(otp_oc);
otp_oc->get_keymgr_secret(s->otp, OTP_KEYMGR_SECRET_CREATOR_SEED, &secret);
OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
oc->get_keymgr_secret(oi, OTP_KEYMGR_SECRET_CREATOR_SEED, &secret);

ot_keymgr_dpe_kdf_push_bytes(s, secret.secret, OT_OTP_KEYMGR_SECRET_SIZE);
*dvalid &= ot_keymgr_dpe_valid_data_check(secret.secret,
Expand Down Expand Up @@ -1076,8 +1076,9 @@ static size_t ot_keymgr_dpe_kdf_append_km_div(OtKeyMgrDpeState *s, bool *dvalid)

static size_t ot_keymgr_dpe_kdf_append_dev_id(OtKeyMgrDpeState *s, bool *dvalid)
{
OtOTPClass *otp_oc = OBJECT_GET_CLASS(OtOTPClass, s->otp, TYPE_OT_OTP);
const OtOTPHWCfg *hw_cfg = otp_oc->get_hw_cfg(s->otp);
OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
const OtOTPHWCfg *hw_cfg = oc->get_hw_cfg(oi);

ot_keymgr_dpe_kdf_push_bytes(s, hw_cfg->device_id,
OT_OTP_HWCFG_DEVICE_ID_BYTES);
Expand Down Expand Up @@ -1106,8 +1107,9 @@ ot_keymgr_dpe_kdf_append_owner_seed(OtKeyMgrDpeState *s, bool *dvalid)
{
OtOTPKeyMgrSecret secret = { 0u };

OtOTPClass *otp_oc = OBJECT_GET_CLASS(OtOTPClass, s->otp, TYPE_OT_OTP);
otp_oc->get_keymgr_secret(s->otp, OTP_KEYMGR_SECRET_OWNER_SEED, &secret);
OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
oc->get_keymgr_secret(oi, OTP_KEYMGR_SECRET_OWNER_SEED, &secret);

ot_keymgr_dpe_kdf_push_bytes(s, secret.secret, OT_OTP_KEYMGR_SECRET_SIZE);
*dvalid &= ot_keymgr_dpe_valid_data_check(secret.secret,
Expand Down Expand Up @@ -1445,11 +1447,11 @@ static void ot_keymgr_dpe_xchange_main_fsm_state(
static void ot_keymgr_dpe_get_root_key(
OtKeyMgrDpeState *s, OtOTPKeyMgrSecret *share0, OtOTPKeyMgrSecret *share1)
{
OtOTPClass *oc = OBJECT_GET_CLASS(OtOTPClass, s->otp, TYPE_OT_OTP);
g_assert(oc);
oc->get_keymgr_secret(s->otp, OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0,
OtOTPIfClass *oc = OT_OTP_IF_GET_CLASS(s->otp_ctrl);
OtOTPIf *oi = OT_OTP_IF(s->otp_ctrl);
oc->get_keymgr_secret(oi, OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0,
share0);
oc->get_keymgr_secret(s->otp, OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1,
oc->get_keymgr_secret(oi, OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1,
share1);

if (trace_event_get_state(TRACE_OT_KEYMGR_DPE_DUMP_CREATOR_ROOT_KEY)) {
Expand Down Expand Up @@ -2004,8 +2006,8 @@ static Property ot_keymgr_dpe_properties[] = {
DEFINE_PROP_UINT8("kmac-app", OtKeyMgrDpeState, kmac_app, UINT8_MAX),
DEFINE_PROP_LINK("lc-ctrl", OtKeyMgrDpeState, lc_ctrl, TYPE_OT_LC_CTRL,
OtLcCtrlState *),
DEFINE_PROP_LINK("otp-ctrl", OtKeyMgrDpeState, otp, TYPE_OT_OTP,
OtOTPState *),
DEFINE_PROP_LINK("otp-ctrl", OtKeyMgrDpeState, otp_ctrl, TYPE_OT_OTP_IF,
DeviceState *),
DEFINE_PROP_LINK("rom0", OtKeyMgrDpeState, rom_ctrl[0], TYPE_OT_ROM_CTRL,
OtRomCtrlState *),
DEFINE_PROP_LINK("rom1", OtKeyMgrDpeState, rom_ctrl[1], TYPE_OT_ROM_CTRL,
Expand Down Expand Up @@ -2061,10 +2063,12 @@ static void ot_keymgr_dpe_reset_enter(Object *obj, ResetType type)
g_assert(s->kmac);
g_assert(s->kmac_app != UINT8_MAX);
g_assert(s->lc_ctrl);
g_assert(s->otp);
g_assert(s->otp_ctrl);
g_assert(s->rom_ctrl[0]);
g_assert(s->rom_ctrl[1]);

(void)OBJECT_CHECK(OtOTPIf, s->otp_ctrl, TYPE_OT_OTP_IF);

s->key_sinks[KEYMGR_DPE_KEY_SINK_KMAC] = DEVICE(s->kmac);

/* reset registers */
Expand Down
Loading
Loading