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"
@@ -350,12 +352,18 @@ REG32(LC_STATE, 2008u)
350352#define SW_CFG_WINDOW_OFFSET 0x800u
351353#define SW_CFG_WINDOW_SIZE (NUM_SW_CFG_WINDOW_WORDS * sizeof(uint32_t))
352354
355+ #define R32_OFF (_r_ ) ((_r_) / sizeof(uint32_t))
356+
353357#define R_LAST_REG (R_SECRET2_DIGEST_1)
354358#define REGS_COUNT (R_LAST_REG + 1u)
355359#define REGS_SIZE (REGS_COUNT * sizeof(uint32_t))
356360#define REG_NAME (_reg_ ) \
357361 ((((_reg_) <= REGS_COUNT) && REG_NAMES[_reg_]) ? REG_NAMES[_reg_] : "?")
358362
363+ /* note: useless casts are required for GCC linter */
364+ static_assert ((unsigned )R_STATUS == (unsigned )R_OTP_FIRST_IMPL_REG ,
365+ "Invalid register address" );
366+
359367typedef enum {
360368 OTP_PART_VENDOR_TEST ,
361369 OTP_PART_CREATOR_SW_CFG ,
@@ -466,11 +474,13 @@ static const char *REG_NAMES[REGS_COUNT] = {
466474};
467475#undef REG_NAME_ENTRY
468476
477+ #define OT_OTP_NAME_ENTRY (_st_ ) [OT_OTP_##_st_] = stringify(OT_OTP_##_st_)
478+
469479static const char * OTP_TOKEN_NAMES [] = {
470480 /* clang-format off */
471- OTP_NAME_ENTRY ( OTP_TOKEN_TEST_UNLOCK ),
472- OTP_NAME_ENTRY ( OTP_TOKEN_TEST_EXIT ),
473- OTP_NAME_ENTRY ( OTP_TOKEN_RMA ),
481+ OT_OTP_NAME_ENTRY ( TOKEN_TEST_UNLOCK ),
482+ OT_OTP_NAME_ENTRY ( TOKEN_TEST_EXIT ),
483+ OT_OTP_NAME_ENTRY ( TOKEN_RMA ),
474484 /* clang-format on */
475485};
476486
@@ -652,11 +662,11 @@ static void ot_otp_eg_reg_write(void *opaque, hwaddr addr, uint64_t value,
652662 s -> regs [reg ] &= val32 ; /* RW0C */
653663 break ;
654664 case R_DIRECT_ACCESS_CMD :
655- if (FIELD_EX32 (val32 , DIRECT_ACCESS_CMD , RD )) {
665+ if (FIELD_EX32 (val32 , OT_OTP_DIRECT_ACCESS_CMD , RD )) {
656666 c -> dai_read (s );
657- } else if (FIELD_EX32 (val32 , DIRECT_ACCESS_CMD , WR )) {
667+ } else if (FIELD_EX32 (val32 , OT_OTP_DIRECT_ACCESS_CMD , WR )) {
658668 c -> dai_write (s );
659- } else if (FIELD_EX32 (val32 , DIRECT_ACCESS_CMD , DIGEST )) {
669+ } else if (FIELD_EX32 (val32 , OT_OTP_DIRECT_ACCESS_CMD , DIGEST )) {
660670 c -> dai_digest (s );
661671 }
662672 break ;
@@ -669,7 +679,7 @@ static void ot_otp_eg_reg_write(void *opaque, hwaddr addr, uint64_t value,
669679 s -> regs [reg ] = val32 ;
670680 break ;
671681 case R_VENDOR_TEST_READ_LOCK ... R_ROT_CREATOR_AUTH_STATE_READ_LOCK :
672- val32 &= READ_LOCK_MASK ;
682+ val32 &= OT_OTP_READ_LOCK_MASK ;
673683 s -> regs [reg ] &= val32 ; /* RW0C */
674684 break ;
675685 case R_CHECK_TRIGGER_REGWEN :
@@ -862,7 +872,7 @@ static MemTxResult ot_otp_eg_swcfg_read_with_attrs(
862872
863873 if (ot_otp_engine_is_buffered (s , part_ix )) {
864874 trace_ot_otp_access_error_on (s -> ot_id , partition , addr , "buffered" );
865- c -> set_error (s , part_ix , OTP_ACCESS_ERROR );
875+ c -> set_error (s , part_ix , OT_OTP_ACCESS_ERROR );
866876
867877 /* real HW seems to stall the Tile Link bus in this case */
868878 return MEMTX_ACCESS_ERROR ;
@@ -874,13 +884,13 @@ static MemTxResult ot_otp_eg_swcfg_read_with_attrs(
874884
875885 if (!is_readable && !(is_digest || is_zer )) {
876886 trace_ot_otp_access_error_on (s -> ot_id , partition , addr , "not readable" );
877- c -> set_error (s , part_ix , OTP_ACCESS_ERROR );
887+ c -> set_error (s , part_ix , OT_OTP_ACCESS_ERROR );
878888
879889 return MEMTX_DECODE_ERROR ;
880890 }
881891
882892 uint32_t val32 = s -> otp -> data [reg ];
883- c -> set_error (s , part_ix , OTP_NO_ERROR );
893+ c -> set_error (s , part_ix , OT_OTP_NO_ERROR );
884894
885895 uint64_t pc ;
886896
@@ -934,18 +944,18 @@ static void ot_otp_eg_get_keymgr_secret(
934944 size_t offset ;
935945
936946 switch (type ) {
937- case OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0 :
947+ case OT_OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE0 :
938948 partition = OTP_PART_SECRET2 ;
939949 offset =
940950 A_SECRET2_CREATOR_ROOT_KEY_SHARE0 - s -> part_descs [partition ].offset ;
941951 break ;
942- case OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1 :
952+ case OT_OTP_KEYMGR_SECRET_CREATOR_ROOT_KEY_SHARE1 :
943953 partition = OTP_PART_SECRET2 ;
944954 offset =
945955 A_SECRET2_CREATOR_ROOT_KEY_SHARE1 - s -> part_descs [partition ].offset ;
946956 break ;
947- case OTP_KEYMGR_SECRET_CREATOR_SEED :
948- case OTP_KEYMGR_SECRET_OWNER_SEED :
957+ case OT_OTP_KEYMGR_SECRET_CREATOR_SEED :
958+ case OT_OTP_KEYMGR_SECRET_OWNER_SEED :
949959 default :
950960 error_report ("%s: %s: invalid OTP keymgr secret type: %d" , __func__ ,
951961 s -> ot_id , type );
@@ -1022,20 +1032,20 @@ static void ot_otp_eg_pwr_load_tokens(OtOTPEngineState *s)
10221032
10231033 static_assert (sizeof (OtOTPTokenValue ) == 16u , "Invalid token size" );
10241034
1025- for (unsigned tkx = 0 ; tkx < OTP_TOKEN_COUNT ; tkx ++ ) {
1035+ for (unsigned tkx = 0 ; tkx < OT_OTP_TOKEN_COUNT ; tkx ++ ) {
10261036 unsigned partition ;
10271037 uint32_t secret_addr ;
10281038
10291039 switch (tkx ) {
1030- case OTP_TOKEN_TEST_UNLOCK :
1040+ case OT_OTP_TOKEN_TEST_UNLOCK :
10311041 partition = (unsigned )OTP_PART_SECRET0 ;
10321042 secret_addr = A_SECRET0_TEST_UNLOCK_TOKEN ;
10331043 break ;
1034- case OTP_TOKEN_TEST_EXIT :
1044+ case OT_OTP_TOKEN_TEST_EXIT :
10351045 partition = (unsigned )OTP_PART_SECRET0 ;
10361046 secret_addr = A_SECRET0_TEST_EXIT_TOKEN ;
10371047 break ;
1038- case OTP_TOKEN_RMA :
1048+ case OT_OTP_TOKEN_RMA :
10391049 partition = (unsigned )OTP_PART_SECRET2 ;
10401050 secret_addr = A_SECRET2_RMA_TOKEN ;
10411051 break ;
@@ -1181,11 +1191,11 @@ static void ot_otp_eg_class_init(ObjectClass *klass, void *data)
11811191 ic -> part_descs [part_ix ].zer_offset == UINT16_MAX );
11821192 }
11831193
1184- g_assert (OT_OTP_KEY_SEEDS [OTP_KEY_FLASH_ADDR ].size ==
1194+ g_assert (OT_OTP_KEY_SEEDS [OT_OTP_KEY_FLASH_ADDR ].size ==
11851195 SECRET1_FLASH_ADDR_KEY_SEED_SIZE );
1186- g_assert (OT_OTP_KEY_SEEDS [OTP_KEY_FLASH_DATA ].size ==
1196+ g_assert (OT_OTP_KEY_SEEDS [OT_OTP_KEY_FLASH_DATA ].size ==
11871197 SECRET1_FLASH_DATA_KEY_SEED_SIZE );
1188- g_assert (OT_OTP_KEY_SEEDS [OTP_KEY_SRAM ].size ==
1198+ g_assert (OT_OTP_KEY_SEEDS [OT_OTP_KEY_SRAM ].size ==
11891199 SECRET1_SRAM_DATA_KEY_SEED_SIZE );
11901200}
11911201
0 commit comments