2828 * THE SOFTWARE.
2929 */
3030
31+ #define OT_OTP_COMPORTABLE_REGS
32+
3133#include "qemu/osdep.h"
3234#include "qemu/log.h"
3335#include "qom/object.h"
@@ -351,12 +353,16 @@ REG32(LC_STATE, 2008u)
351353#define SW_CFG_WINDOW 0x800u
352354#define SW_CFG_WINDOW_SIZE (NUM_SW_CFG_WINDOW_WORDS * sizeof(uint32_t))
353355
356+ #define R32_OFF (_r_ ) ((_r_) / sizeof(uint32_t))
357+
354358#define R_LAST_REG (R_SECRET2_DIGEST_1)
355359#define REGS_COUNT (R_LAST_REG + 1u)
356360#define REGS_SIZE (REGS_COUNT * sizeof(uint32_t))
357361#define REG_NAME (_reg_ ) \
358362 ((((_reg_) <= REGS_COUNT) && REG_NAMES[_reg_]) ? REG_NAMES[_reg_] : "?")
359363
364+ static_assert (R_STATUS == R_OTP_FIRST_IMPL_REG , "Invalid register address" );
365+
360366typedef enum {
361367 OTP_PART_VENDOR_TEST ,
362368 OTP_PART_CREATOR_SW_CFG ,
@@ -467,11 +473,13 @@ static const char *REG_NAMES[REGS_COUNT] = {
467473};
468474#undef REG_NAME_ENTRY
469475
476+ #define OT_OTP_NAME_ENTRY (_st_ ) [OT_OTP_##_st_] = stringify(OT_OTP_##_st_)
477+
470478static const char * OTP_TOKEN_NAMES [] = {
471479 /* clang-format off */
472- OTP_NAME_ENTRY ( OTP_TOKEN_TEST_UNLOCK ),
473- OTP_NAME_ENTRY ( OTP_TOKEN_TEST_EXIT ),
474- OTP_NAME_ENTRY ( OTP_TOKEN_RMA ),
480+ OT_OTP_NAME_ENTRY ( TOKEN_TEST_UNLOCK ),
481+ OT_OTP_NAME_ENTRY ( TOKEN_TEST_EXIT ),
482+ OT_OTP_NAME_ENTRY ( TOKEN_RMA ),
475483 /* clang-format on */
476484};
477485
@@ -653,11 +661,11 @@ static void ot_otp_eg_reg_write(void *opaque, hwaddr addr, uint64_t value,
653661 s -> regs [reg ] &= val32 ; /* RW0C */
654662 break ;
655663 case R_DIRECT_ACCESS_CMD :
656- if (FIELD_EX32 (val32 , DIRECT_ACCESS_CMD , RD )) {
664+ if (FIELD_EX32 (val32 , OT_OTP_DIRECT_ACCESS_CMD , RD )) {
657665 c -> dai_read (s );
658- } else if (FIELD_EX32 (val32 , DIRECT_ACCESS_CMD , WR )) {
666+ } else if (FIELD_EX32 (val32 , OT_OTP_DIRECT_ACCESS_CMD , WR )) {
659667 c -> dai_write (s );
660- } else if (FIELD_EX32 (val32 , DIRECT_ACCESS_CMD , DIGEST )) {
668+ } else if (FIELD_EX32 (val32 , OT_OTP_DIRECT_ACCESS_CMD , DIGEST )) {
661669 c -> dai_digest (s );
662670 }
663671 break ;
@@ -670,7 +678,7 @@ static void ot_otp_eg_reg_write(void *opaque, hwaddr addr, uint64_t value,
670678 s -> regs [reg ] = val32 ;
671679 break ;
672680 case R_VENDOR_TEST_READ_LOCK ... R_ROT_CREATOR_AUTH_STATE_READ_LOCK :
673- val32 &= READ_LOCK_MASK ;
681+ val32 &= OT_OTP_READ_LOCK_MASK ;
674682 s -> regs [reg ] &= val32 ; /* RW0C */
675683 break ;
676684 case R_CHECK_TRIGGER_REGWEN :
@@ -863,7 +871,7 @@ static MemTxResult ot_otp_eg_swcfg_read_with_attrs(
863871
864872 if (ot_otp_engine_is_buffered (s , part_ix )) {
865873 trace_ot_otp_access_error_on (s -> ot_id , partition , addr , "buffered" );
866- c -> set_error (s , part_ix , OTP_ACCESS_ERROR );
874+ c -> set_error (s , part_ix , OT_OTP_ACCESS_ERROR );
867875
868876 /* real HW seems to stall the Tile Link bus in this case */
869877 return MEMTX_ACCESS_ERROR ;
@@ -875,13 +883,13 @@ static MemTxResult ot_otp_eg_swcfg_read_with_attrs(
875883
876884 if (!is_readable && !(is_digest || is_zer )) {
877885 trace_ot_otp_access_error_on (s -> ot_id , partition , addr , "not readable" );
878- c -> set_error (s , part_ix , OTP_ACCESS_ERROR );
886+ c -> set_error (s , part_ix , OT_OTP_ACCESS_ERROR );
879887
880888 return MEMTX_DECODE_ERROR ;
881889 }
882890
883891 uint32_t val32 = s -> otp -> data [reg ];
884- c -> set_error (s , part_ix , OTP_NO_ERROR );
892+ c -> set_error (s , part_ix , OT_OTP_NO_ERROR );
885893
886894 uint64_t pc ;
887895
@@ -935,18 +943,18 @@ static void ot_otp_eg_get_keymgr_secret(
935943 size_t offset ;
936944
937945 switch (type ) {
938- case OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0 :
946+ case OT_OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0 :
939947 partition = OTP_PART_SECRET2 ;
940948 offset =
941949 A_SECRET2_CREATOR_ROOT_KEY_SHARE0 - s -> part_descs [partition ].offset ;
942950 break ;
943- case OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1 :
951+ case OT_OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1 :
944952 partition = OTP_PART_SECRET2 ;
945953 offset =
946954 A_SECRET2_CREATOR_ROOT_KEY_SHARE1 - s -> part_descs [partition ].offset ;
947955 break ;
948- case OTP_KEYMGR_SECRET_CREATOR_SEED :
949- case OTP_KEYMGR_SECRET_OWNER_SEED :
956+ case OT_OTP_KEYMGR_SECRET_CREATOR_SEED :
957+ case OT_OTP_KEYMGR_SECRET_OWNER_SEED :
950958 default :
951959 error_report ("%s: %s: invalid OTP keymgr secret type: %d" , __func__ ,
952960 s -> ot_id , type );
@@ -1023,20 +1031,20 @@ static void ot_otp_eg_pwr_load_tokens(OtOTPEngineState *s)
10231031
10241032 static_assert (sizeof (OtOTPTokenValue ) == 16u , "Invalid token size" );
10251033
1026- for (unsigned tkx = 0 ; tkx < OTP_TOKEN_COUNT ; tkx ++ ) {
1034+ for (unsigned tkx = 0 ; tkx < OT_OTP_TOKEN_COUNT ; tkx ++ ) {
10271035 unsigned partition ;
10281036 uint32_t secret_addr ;
10291037
10301038 switch (tkx ) {
1031- case OTP_TOKEN_TEST_UNLOCK :
1039+ case OT_OTP_TOKEN_TEST_UNLOCK :
10321040 partition = (unsigned )OTP_PART_SECRET0 ;
10331041 secret_addr = A_SECRET0_TEST_UNLOCK_TOKEN ;
10341042 break ;
1035- case OTP_TOKEN_TEST_EXIT :
1043+ case OT_OTP_TOKEN_TEST_EXIT :
10361044 partition = (unsigned )OTP_PART_SECRET0 ;
10371045 secret_addr = A_SECRET0_TEST_EXIT_TOKEN ;
10381046 break ;
1039- case OTP_TOKEN_RMA :
1047+ case OT_OTP_TOKEN_RMA :
10401048 partition = (unsigned )OTP_PART_SECRET2 ;
10411049 secret_addr = A_SECRET2_RMA_TOKEN ;
10421050 break ;
@@ -1177,11 +1185,11 @@ static void ot_otp_eg_class_init(ObjectClass *klass, void *data)
11771185 ic -> key_seeds = OT_OTP_KEY_SEEDS ;
11781186 ic -> has_flash_support = true;
11791187
1180- g_assert (OT_OTP_KEY_SEEDS [OTP_KEY_FLASH_ADDR ].size ==
1188+ g_assert (OT_OTP_KEY_SEEDS [OT_OTP_KEY_FLASH_ADDR ].size ==
11811189 SECRET1_FLASH_ADDR_KEY_SEED_SIZE );
1182- g_assert (OT_OTP_KEY_SEEDS [OTP_KEY_FLASH_DATA ].size ==
1190+ g_assert (OT_OTP_KEY_SEEDS [OT_OTP_KEY_FLASH_DATA ].size ==
11831191 SECRET1_FLASH_DATA_KEY_SEED_SIZE );
1184- g_assert (OT_OTP_KEY_SEEDS [OTP_KEY_SRAM ].size ==
1192+ g_assert (OT_OTP_KEY_SEEDS [OT_OTP_KEY_SRAM ].size ==
11851193 SECRET1_SRAM_DATA_KEY_SEED_SIZE );
11861194}
11871195
0 commit comments