1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License as published by the 6 * Free Software Foundation; either version 2 of the License, or (at your 7 * option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 19 #ifndef __DRV_OTP_H__ 20 #define __DRV_OTP_H__ 21 22 #include "hi_type.h" 23 #include "hi_common_otp.h" 24 #include "drv_ioctl_otp.h" 25 26 #define OTP_USER_WORK_MODE 0x0000 27 #define OTP_USER_OP_START 0x0004 28 #define OTP_USER_KEY_INDEX 0x0008 29 #define OTP_USER_KEY_DATA0 0x000c 30 #define OTP_USER_KEY_DATA1 0x0010 31 #define OTP_USER_KEY_DATA2 0x0014 32 #define OTP_USER_KEY_DATA3 0x0018 33 #define OTP_USER_KEY_DATA4 0x001c 34 #define OTP_USER_KEY_DATA5 0x0020 35 #define OTP_USER_KEY_DATA6 0x0024 36 #define OTP_USER_KEY_DATA7 0x0028 37 #define OTP_USER_KEY_DATA8 0x002c 38 #define OTP_USER_FLAG_VALUE 0x0030 39 #define OTP_USER_FLAG_INDEX 0x0034 40 #define OTP_USER_REV_ADDR 0x0038 41 #define OTP_USER_REV_WDATA 0x003c 42 #define OTP_USER_REV_RDATA 0x0040 43 #define OTP_USER_LOCK_STA0 0x0044 44 #define OTP_USER_LOCK_STA1 0x0048 45 #define OTP_USER_CTRL_STA 0x004c 46 #define OTP_WAIT_TIME_OUT 10000 47 #define OTP_OP_START_VAL 0x1acce551 48 #define OTP_USER_INDEX_ROOM_MAX 0x37F 49 50 #define OTP_USER_KEY_MAX_BYTES 32 51 #define OTP_USER_KEY_MAX_WORDS (OTP_USER_KEY_MAX_BYTES / 4) 52 53 typedef union { 54 struct { 55 hi_u32 secure_boot_en: 1; /* 0 */ 56 hi_u32 ddr_ca_en: 1; /* 1 */ 57 hi_u32 jtag_ca_en: 1; /* 2 */ 58 hi_u32 reserved: 1; /* 3 */ 59 hi_u32 jtag_prt_mode: 2; /* [4:5] */ 60 hi_u32 jtag_prt_mode_lock_en: 1; /* 6 */ 61 hi_u32 secure_iso_en: 1; /* 7 */ 62 hi_u32 uboot_redundance: 1; /* 8 */ 63 hi_u32 reserved_flag1: 1; /* 9 */ 64 hi_u32 reserved_flag2: 21; /* [10:30] */ 65 hi_u32 reserved_flag2_lock_en: 1; /* 31 */ 66 } bits; 67 hi_u32 u32; 68 } otp_user_flag_value; 69 70 typedef union { 71 struct { 72 hi_u32 secure_boot_en_lock: 1; /* 0 */ 73 hi_u32 ddr_ca_en_lock: 1; /* 1 */ 74 hi_u32 jtag_pw_id_lock: 1; /* 2 */ 75 hi_u32 jtag_pw_lock: 1; /* 3 */ 76 hi_u32 root_key_lock: 1; /* 4 */ 77 hi_u32 key0_lock: 1; /* 5 */ 78 hi_u32 key1_lock: 1; /* 6 */ 79 hi_u32 key2_lock: 1; /* 7 */ 80 hi_u32 key3_lock: 1; /* 8 */ 81 hi_u32 jtag_ca_en_lock: 1; /* 9 */ 82 hi_u32 jtag_prt_mode_lock: 1; /* 10 */ 83 hi_u32 reserved2: 1; /* 11 */ 84 hi_u32 uboot_redundance_lock: 1; /* 12 */ 85 hi_u32 reserved_flag1_lock: 1; /* 13 */ 86 hi_u32 reserved_flag2_lock: 1; /* 14 */ 87 hi_u32 hmac_key_lock: 1; /* 15 */ 88 hi_u32 reserved3: 16; /* [16:31] */ 89 } bits; 90 hi_u32 u32; 91 } otp_user_lock_sta0; 92 93 typedef enum { 94 OTP_CTRL_STA_OP_BUSY = 0, 95 OTP_CTRL_STA_USER_CMD_FINISH, 96 OTP_CTRL_STA_USER_LOCK_ERR, 97 OTP_CTRL_STA_KEY_RD_BACK_CHECK_ERR, 98 OTP_CTRL_STA_KEY_CRC_CHECK_OK_FLAG, 99 OTP_CTRL_STA_USER_REV_RD_FINISH, 100 OTP_CTRL_STA_USER_REV_PGM_FINISH, 101 OTP_CTRL_STA_FLAG_PGM_FINISH, 102 OTP_CTRL_STA_KEY_CRC_CHECK_FINISH, 103 OTP_CTRL_STA_KEY_PGM_FINISH, 104 OTP_CTRL_STA_KEY_LOAD_FINISH, 105 OTP_CTRL_STA_RD_LOCK_STA_FINISH, 106 OTP_CTRL_STA_KEY0_INDEX_FINISH, 107 OTP_CTRL_STA_KEY1_INDEX_FINISH, 108 OTP_CTRL_STA_KEY2_INDEX_FINISH, 109 OTP_CTRL_STA_KEY3_INDEX_FINISH, 110 OTP_CTRL_STA_USER_REV_ADDR0_FINISH, 111 OTP_CTRL_STA_USER_REV_ADDR1_FINISH, 112 OTP_CTRL_STA_USER_REV_ADDR2_FINISH, 113 OTP_CTRL_STA_USER_REV_ADDR3_FINISH, 114 OTP_CTRL_STA_USER_REV_ADDR4_FINISH, 115 OTP_CTRL_STA_USER_REV_ADDR5_FINISH, 116 OTP_CTRL_STA_USER_REV_ADDR6_FINISH, 117 OTP_CTRL_STA_USER_REV_ADDR7_FINISH, 118 OTP_CTRL_STA_FLAG_INDEX_FINISH, 119 OTP_CTRL_STA_BUTT, 120 OTP_CTRL_STA_INVALID, 121 } otp_user_ctrl_sta; 122 123 typedef enum { 124 OTP_WORK_MODE_READ_LOCK_STA = 0, 125 OTP_WORK_MODE_LOAD_CIPHER_KEY, 126 OTP_WORK_MODE_BURN_KEY, 127 OTP_WORK_MODE_VERIFY_KEY_CRC, 128 OTP_WORK_MODE_ENABLE_FLAG_CFG, 129 OTP_WORK_MODE_WRITE_USER_ROOM, 130 OTP_WORK_MODE_READ_USER_ROOM, 131 OTP_WORK_MODE_BUTT, 132 } otp_user_work_mode; 133 134 typedef enum { 135 OTP_USER_KEY0 = 0, 136 OTP_USER_KEY1, 137 OTP_USER_KEY2, 138 OTP_USER_KEY3, 139 OTP_USER_KEY_JTAG_PW_ID, 140 OTP_USER_KEY_JTAG_PW, 141 OTP_USER_KEY_ROOTKEY, 142 OTP_USER_KEY_HMACKEY, 143 OTP_USER_KEY_BUTT, 144 } otp_user_key_index; 145 146 typedef enum { 147 OTP_USER_FLAG_SECURE_BOOT_EN = 0, 148 OTP_USER_FLAG_DDR_CA_EN, 149 OTP_USER_FLAG_JTAG_CA_EN, 150 OTP_USER_FLAG_JTAG_PRT_MODE, 151 OTP_USER_FLAG_SECURE_ISO_EN, 152 OTP_USER_FLAG_UBOOT_REDUNDANCE, 153 OTP_USER_FLAG_RESERVED, 154 OTP_USER_FLAG_BUTT, 155 } otp_user_flag_index; 156 157 hi_s32 drv_otp_set_user_data(const hi_char *field_name, 158 hi_u32 offset, const hi_u8 *value, hi_u32 value_len); 159 160 hi_s32 drv_otp_get_user_data(const hi_char *field_name, 161 hi_u32 offset, hi_u8 *value, hi_u32 value_len); 162 163 hi_s32 drv_otp_burn_product_pv(const hi_otp_burn_pv_item *pv, hi_u32 num); 164 165 hi_s32 drv_otp_read_product_pv(hi_otp_burn_pv_item *pv, hi_u32 num); 166 167 hi_s32 drv_otp_get_key_verify_status(const hi_char *key_name, hi_bool *status); 168 169 hi_s32 drv_otp_load_key_to_klad(const hi_char *key_name); 170 171 #endif /* __DRV_OTP_H__ */