Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
Peng Fan | c88036d | 2023-06-15 18:09:08 +0800 | [diff] [blame] | 3 | * Copyright 2020, 2023 NXP |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 4 | * |
| 5 | */ |
| 6 | |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 7 | #include <hang.h> |
| 8 | #include <malloc.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <dm.h> |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 11 | #include <asm/mach-imx/ele_api.h> |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 12 | #include <misc.h> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Peng Fan | 16426c8 | 2023-06-15 18:09:09 +0800 | [diff] [blame] | 16 | static u32 compute_crc(const struct ele_msg *msg) |
| 17 | { |
| 18 | u32 crc = 0; |
| 19 | size_t i = 0; |
| 20 | u32 *data = (u32 *)msg; |
| 21 | |
| 22 | for (i = 0; i < (msg->size - 1); i++) |
| 23 | crc ^= data[i]; |
| 24 | |
| 25 | return crc; |
| 26 | } |
| 27 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 28 | int ele_release_rdc(u8 core_id, u8 xrdc, u32 *response) |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 29 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 30 | struct udevice *dev = gd->arch.ele_dev; |
| 31 | int size = sizeof(struct ele_msg); |
| 32 | struct ele_msg msg; |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 33 | int ret; |
| 34 | |
| 35 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 36 | printf("ele dev is not initialized\n"); |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 37 | return -ENODEV; |
| 38 | } |
| 39 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 40 | msg.version = ELE_VERSION; |
| 41 | msg.tag = ELE_CMD_TAG; |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 42 | msg.size = 2; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 43 | msg.command = ELE_RELEASE_RDC_REQ; |
Ye Li | d4b3ba3 | 2022-07-26 16:40:51 +0800 | [diff] [blame] | 44 | switch (xrdc) { |
| 45 | case 0: |
Ye Li | acc9afe | 2021-08-07 16:00:53 +0800 | [diff] [blame] | 46 | msg.data[0] = (0x74 << 8) | core_id; |
Ye Li | d4b3ba3 | 2022-07-26 16:40:51 +0800 | [diff] [blame] | 47 | break; |
| 48 | case 1: |
| 49 | msg.data[0] = (0x78 << 8) | core_id; |
| 50 | break; |
| 51 | case 2: |
| 52 | msg.data[0] = (0x82 << 8) | core_id; |
| 53 | break; |
| 54 | case 3: |
| 55 | msg.data[0] = (0x86 << 8) | core_id; |
| 56 | break; |
| 57 | default: |
| 58 | printf("Error: wrong xrdc index %u\n", xrdc); |
| 59 | return -EINVAL; |
| 60 | } |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 61 | |
| 62 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 63 | if (ret) |
| 64 | printf("Error: %s: ret %d, core id %u, response 0x%x\n", |
| 65 | __func__, ret, core_id, msg.data[0]); |
| 66 | |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 67 | if (response) |
| 68 | *response = msg.data[0]; |
| 69 | |
| 70 | return ret; |
| 71 | } |
| 72 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 73 | int ele_auth_oem_ctnr(ulong ctnr_addr, u32 *response) |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 74 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 75 | struct udevice *dev = gd->arch.ele_dev; |
| 76 | int size = sizeof(struct ele_msg); |
| 77 | struct ele_msg msg; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 78 | int ret; |
| 79 | |
| 80 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 81 | printf("ele dev is not initialized\n"); |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 82 | return -ENODEV; |
| 83 | } |
| 84 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 85 | msg.version = ELE_VERSION; |
| 86 | msg.tag = ELE_CMD_TAG; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 87 | msg.size = 3; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 88 | msg.command = ELE_OEM_CNTN_AUTH_REQ; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 89 | msg.data[0] = upper_32_bits(ctnr_addr); |
| 90 | msg.data[1] = lower_32_bits(ctnr_addr); |
| 91 | |
| 92 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 93 | if (ret) |
| 94 | printf("Error: %s: ret %d, cntr_addr 0x%lx, response 0x%x\n", |
| 95 | __func__, ret, ctnr_addr, msg.data[0]); |
| 96 | |
| 97 | if (response) |
| 98 | *response = msg.data[0]; |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 103 | int ele_release_container(u32 *response) |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 104 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 105 | struct udevice *dev = gd->arch.ele_dev; |
| 106 | int size = sizeof(struct ele_msg); |
| 107 | struct ele_msg msg; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 108 | int ret; |
| 109 | |
| 110 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 111 | printf("ele dev is not initialized\n"); |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 112 | return -ENODEV; |
| 113 | } |
| 114 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 115 | msg.version = ELE_VERSION; |
| 116 | msg.tag = ELE_CMD_TAG; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 117 | msg.size = 1; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 118 | msg.command = ELE_RELEASE_CONTAINER_REQ; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 119 | |
| 120 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 121 | if (ret) |
| 122 | printf("Error: %s: ret %d, response 0x%x\n", |
| 123 | __func__, ret, msg.data[0]); |
| 124 | |
| 125 | if (response) |
| 126 | *response = msg.data[0]; |
| 127 | |
| 128 | return ret; |
| 129 | } |
| 130 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 131 | int ele_verify_image(u32 img_id, u32 *response) |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 132 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 133 | struct udevice *dev = gd->arch.ele_dev; |
| 134 | int size = sizeof(struct ele_msg); |
| 135 | struct ele_msg msg; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 136 | int ret; |
| 137 | |
| 138 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 139 | printf("ele dev is not initialized\n"); |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 140 | return -ENODEV; |
| 141 | } |
| 142 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 143 | msg.version = ELE_VERSION; |
| 144 | msg.tag = ELE_CMD_TAG; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 145 | msg.size = 2; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 146 | msg.command = ELE_VERIFY_IMAGE_REQ; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 147 | msg.data[0] = 1 << img_id; |
| 148 | |
| 149 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 150 | if (ret) |
| 151 | printf("Error: %s: ret %d, img_id %u, response 0x%x\n", |
| 152 | __func__, ret, img_id, msg.data[0]); |
| 153 | |
| 154 | if (response) |
| 155 | *response = msg.data[0]; |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 160 | int ele_forward_lifecycle(u16 life_cycle, u32 *response) |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 161 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 162 | struct udevice *dev = gd->arch.ele_dev; |
| 163 | int size = sizeof(struct ele_msg); |
| 164 | struct ele_msg msg; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 165 | int ret; |
| 166 | |
| 167 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 168 | printf("ele dev is not initialized\n"); |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 169 | return -ENODEV; |
| 170 | } |
| 171 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 172 | msg.version = ELE_VERSION; |
| 173 | msg.tag = ELE_CMD_TAG; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 174 | msg.size = 2; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 175 | msg.command = ELE_FWD_LIFECYCLE_UP_REQ; |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame] | 176 | msg.data[0] = life_cycle; |
| 177 | |
| 178 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 179 | if (ret) |
| 180 | printf("Error: %s: ret %d, life_cycle 0x%x, response 0x%x\n", |
| 181 | __func__, ret, life_cycle, msg.data[0]); |
| 182 | |
| 183 | if (response) |
| 184 | *response = msg.data[0]; |
| 185 | |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 186 | return ret; |
| 187 | } |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 188 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 189 | int ele_read_common_fuse(u16 fuse_id, u32 *fuse_words, u32 fuse_num, u32 *response) |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 190 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 191 | struct udevice *dev = gd->arch.ele_dev; |
| 192 | int size = sizeof(struct ele_msg); |
| 193 | struct ele_msg msg; |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 194 | int ret; |
| 195 | |
| 196 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 197 | printf("ele dev is not initialized\n"); |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 198 | return -ENODEV; |
| 199 | } |
| 200 | |
| 201 | if (!fuse_words) { |
| 202 | printf("Invalid parameters for fuse read\n"); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
| 206 | if ((fuse_id != 1 && fuse_num != 1) || |
| 207 | (fuse_id == 1 && fuse_num != 4)) { |
| 208 | printf("Invalid fuse number parameter\n"); |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 212 | msg.version = ELE_VERSION; |
| 213 | msg.tag = ELE_CMD_TAG; |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 214 | msg.size = 2; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 215 | msg.command = ELE_READ_FUSE_REQ; |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 216 | msg.data[0] = fuse_id; |
| 217 | |
| 218 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 219 | if (ret) |
| 220 | printf("Error: %s: ret %d, fuse_id 0x%x, response 0x%x\n", |
| 221 | __func__, ret, fuse_id, msg.data[0]); |
| 222 | |
| 223 | if (response) |
| 224 | *response = msg.data[0]; |
| 225 | |
| 226 | fuse_words[0] = msg.data[1]; |
| 227 | if (fuse_id == 1) { |
| 228 | /* OTP_UNIQ_ID */ |
| 229 | fuse_words[1] = msg.data[2]; |
| 230 | fuse_words[2] = msg.data[3]; |
| 231 | fuse_words[3] = msg.data[4]; |
| 232 | } |
| 233 | |
| 234 | return ret; |
| 235 | } |
| 236 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 237 | int ele_write_fuse(u16 fuse_id, u32 fuse_val, bool lock, u32 *response) |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 238 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 239 | struct udevice *dev = gd->arch.ele_dev; |
| 240 | int size = sizeof(struct ele_msg); |
| 241 | struct ele_msg msg; |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 242 | int ret; |
| 243 | |
| 244 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 245 | printf("ele dev is not initialized\n"); |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 246 | return -ENODEV; |
| 247 | } |
| 248 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 249 | msg.version = ELE_VERSION; |
| 250 | msg.tag = ELE_CMD_TAG; |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 251 | msg.size = 3; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 252 | msg.command = ELE_WRITE_FUSE_REQ; |
Ye Li | f80a41b | 2021-08-07 16:00:54 +0800 | [diff] [blame] | 253 | msg.data[0] = (32 << 16) | (fuse_id << 5); |
| 254 | if (lock) |
| 255 | msg.data[0] |= (1 << 31); |
| 256 | |
| 257 | msg.data[1] = fuse_val; |
| 258 | |
| 259 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 260 | if (ret) |
| 261 | printf("Error: %s: ret %d, fuse_id 0x%x, response 0x%x\n", |
| 262 | __func__, ret, fuse_id, msg.data[0]); |
| 263 | |
| 264 | if (response) |
| 265 | *response = msg.data[0]; |
| 266 | |
| 267 | return ret; |
| 268 | } |
Clement Faure | 26386ae | 2022-04-06 14:30:19 +0800 | [diff] [blame] | 269 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 270 | int ele_release_caam(u32 core_did, u32 *response) |
Clement Faure | 26386ae | 2022-04-06 14:30:19 +0800 | [diff] [blame] | 271 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 272 | struct udevice *dev = gd->arch.ele_dev; |
| 273 | int size = sizeof(struct ele_msg); |
| 274 | struct ele_msg msg; |
Clement Faure | 26386ae | 2022-04-06 14:30:19 +0800 | [diff] [blame] | 275 | int ret; |
| 276 | |
| 277 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 278 | printf("ele dev is not initialized\n"); |
Clement Faure | 26386ae | 2022-04-06 14:30:19 +0800 | [diff] [blame] | 279 | return -ENODEV; |
| 280 | } |
| 281 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 282 | msg.version = ELE_VERSION; |
| 283 | msg.tag = ELE_CMD_TAG; |
Clement Faure | 26386ae | 2022-04-06 14:30:19 +0800 | [diff] [blame] | 284 | msg.size = 2; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 285 | msg.command = ELE_RELEASE_CAAM_REQ; |
Clement Faure | 26386ae | 2022-04-06 14:30:19 +0800 | [diff] [blame] | 286 | msg.data[0] = core_did; |
| 287 | |
| 288 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 289 | if (ret) |
| 290 | printf("Error: %s: ret %d, response 0x%x\n", |
| 291 | __func__, ret, msg.data[0]); |
| 292 | |
| 293 | if (response) |
| 294 | *response = msg.data[0]; |
| 295 | |
| 296 | return ret; |
| 297 | } |
Ye Li | 0a917da | 2022-04-06 14:30:20 +0800 | [diff] [blame] | 298 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 299 | int ele_get_fw_version(u32 *fw_version, u32 *sha1, u32 *response) |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 300 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 301 | struct udevice *dev = gd->arch.ele_dev; |
| 302 | int size = sizeof(struct ele_msg); |
| 303 | struct ele_msg msg; |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 304 | int ret; |
| 305 | |
| 306 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 307 | printf("ele dev is not initialized\n"); |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 308 | return -ENODEV; |
| 309 | } |
| 310 | |
| 311 | if (!fw_version) { |
| 312 | printf("Invalid parameters for f/w version read\n"); |
| 313 | return -EINVAL; |
| 314 | } |
| 315 | |
| 316 | if (!sha1) { |
| 317 | printf("Invalid parameters for commit sha1\n"); |
| 318 | return -EINVAL; |
| 319 | } |
| 320 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 321 | msg.version = ELE_VERSION; |
| 322 | msg.tag = ELE_CMD_TAG; |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 323 | msg.size = 1; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 324 | msg.command = ELE_GET_FW_VERSION_REQ; |
Gaurav Jain | 580cc7b | 2022-05-11 14:07:55 +0530 | [diff] [blame] | 325 | |
| 326 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 327 | if (ret) |
| 328 | printf("Error: %s: ret %d, response 0x%x\n", |
| 329 | __func__, ret, msg.data[0]); |
| 330 | |
| 331 | if (response) |
| 332 | *response = msg.data[0]; |
| 333 | |
| 334 | *fw_version = msg.data[1]; |
| 335 | *sha1 = msg.data[2]; |
| 336 | |
| 337 | return ret; |
| 338 | } |
| 339 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 340 | int ele_dump_buffer(u32 *buffer, u32 buffer_length) |
Ye Li | 0a917da | 2022-04-06 14:30:20 +0800 | [diff] [blame] | 341 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 342 | struct udevice *dev = gd->arch.ele_dev; |
| 343 | int size = sizeof(struct ele_msg); |
| 344 | struct ele_msg msg; |
Ye Li | 0a917da | 2022-04-06 14:30:20 +0800 | [diff] [blame] | 345 | int ret, i = 0; |
| 346 | |
| 347 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 348 | printf("ele dev is not initialized\n"); |
Ye Li | 0a917da | 2022-04-06 14:30:20 +0800 | [diff] [blame] | 349 | return -ENODEV; |
| 350 | } |
| 351 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 352 | msg.version = ELE_VERSION; |
| 353 | msg.tag = ELE_CMD_TAG; |
Ye Li | 0a917da | 2022-04-06 14:30:20 +0800 | [diff] [blame] | 354 | msg.size = 1; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 355 | msg.command = ELE_DUMP_DEBUG_BUFFER_REQ; |
Ye Li | 0a917da | 2022-04-06 14:30:20 +0800 | [diff] [blame] | 356 | |
| 357 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 358 | if (ret) { |
| 359 | printf("Error: %s: ret %d, response 0x%x\n", |
| 360 | __func__, ret, msg.data[0]); |
| 361 | |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | if (buffer) { |
| 366 | buffer[i++] = *(u32 *)&msg; /* Need dump the response header */ |
| 367 | for (; i < buffer_length && i < msg.size; i++) |
| 368 | buffer[i] = msg.data[i - 1]; |
| 369 | } |
| 370 | |
| 371 | return i; |
| 372 | } |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 373 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 374 | int ele_get_info(struct ele_get_info_data *info, u32 *response) |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 375 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 376 | struct udevice *dev = gd->arch.ele_dev; |
| 377 | int size = sizeof(struct ele_msg); |
| 378 | struct ele_msg msg; |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 379 | int ret; |
| 380 | |
| 381 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 382 | printf("ele dev is not initialized\n"); |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 383 | return -ENODEV; |
| 384 | } |
| 385 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 386 | msg.version = ELE_VERSION; |
| 387 | msg.tag = ELE_CMD_TAG; |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 388 | msg.size = 4; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 389 | msg.command = ELE_GET_INFO_REQ; |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 390 | msg.data[0] = upper_32_bits((ulong)info); |
| 391 | msg.data[1] = lower_32_bits((ulong)info); |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 392 | msg.data[2] = sizeof(struct ele_get_info_data); |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 393 | |
| 394 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 395 | if (ret) |
| 396 | printf("Error: %s: ret %d, response 0x%x\n", |
| 397 | __func__, ret, msg.data[0]); |
| 398 | |
| 399 | if (response) |
| 400 | *response = msg.data[0]; |
| 401 | |
| 402 | return ret; |
| 403 | } |
| 404 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 405 | int ele_get_fw_status(u32 *status, u32 *response) |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 406 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 407 | struct udevice *dev = gd->arch.ele_dev; |
| 408 | int size = sizeof(struct ele_msg); |
| 409 | struct ele_msg msg; |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 410 | int ret; |
| 411 | |
| 412 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 413 | printf("ele dev is not initialized\n"); |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 414 | return -ENODEV; |
| 415 | } |
| 416 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 417 | msg.version = ELE_VERSION; |
| 418 | msg.tag = ELE_CMD_TAG; |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 419 | msg.size = 1; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 420 | msg.command = ELE_GET_FW_STATUS_REQ; |
Peng Fan | cffe2b9 | 2022-07-26 16:40:52 +0800 | [diff] [blame] | 421 | |
| 422 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 423 | if (ret) |
| 424 | printf("Error: %s: ret %d, response 0x%x\n", |
| 425 | __func__, ret, msg.data[0]); |
| 426 | |
| 427 | if (response) |
| 428 | *response = msg.data[0]; |
| 429 | |
| 430 | *status = msg.data[1] & 0xF; |
| 431 | |
| 432 | return ret; |
| 433 | } |
Peng Fan | f6ff140 | 2022-07-26 16:40:53 +0800 | [diff] [blame] | 434 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 435 | int ele_release_m33_trout(void) |
Peng Fan | f6ff140 | 2022-07-26 16:40:53 +0800 | [diff] [blame] | 436 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 437 | struct udevice *dev = gd->arch.ele_dev; |
| 438 | int size = sizeof(struct ele_msg); |
| 439 | struct ele_msg msg; |
Peng Fan | f6ff140 | 2022-07-26 16:40:53 +0800 | [diff] [blame] | 440 | int ret; |
| 441 | |
| 442 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 443 | printf("ele dev is not initialized\n"); |
Peng Fan | f6ff140 | 2022-07-26 16:40:53 +0800 | [diff] [blame] | 444 | return -ENODEV; |
| 445 | } |
| 446 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 447 | msg.version = ELE_VERSION; |
| 448 | msg.tag = ELE_CMD_TAG; |
Peng Fan | f6ff140 | 2022-07-26 16:40:53 +0800 | [diff] [blame] | 449 | msg.size = 1; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 450 | msg.command = ELE_ENABLE_RTC_REQ; |
Peng Fan | f6ff140 | 2022-07-26 16:40:53 +0800 | [diff] [blame] | 451 | |
| 452 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 453 | if (ret) |
| 454 | printf("Error: %s: ret %d, response 0x%x\n", |
| 455 | __func__, ret, msg.data[0]); |
| 456 | |
| 457 | return ret; |
| 458 | } |
Ye Li | 395bfd4 | 2023-01-30 18:39:50 +0800 | [diff] [blame] | 459 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 460 | int ele_get_events(u32 *events, u32 *events_cnt, u32 *response) |
Ye Li | 395bfd4 | 2023-01-30 18:39:50 +0800 | [diff] [blame] | 461 | { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 462 | struct udevice *dev = gd->arch.ele_dev; |
| 463 | int size = sizeof(struct ele_msg); |
| 464 | struct ele_msg msg; |
Ye Li | 395bfd4 | 2023-01-30 18:39:50 +0800 | [diff] [blame] | 465 | int ret, i = 0; |
| 466 | u32 actual_events; |
| 467 | |
| 468 | if (!dev) { |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 469 | printf("ele dev is not initialized\n"); |
Ye Li | 395bfd4 | 2023-01-30 18:39:50 +0800 | [diff] [blame] | 470 | return -ENODEV; |
| 471 | } |
| 472 | |
| 473 | if (!events || !events_cnt || *events_cnt == 0) { |
| 474 | printf("Invalid parameters for %s\n", __func__); |
| 475 | return -EINVAL; |
| 476 | } |
| 477 | |
Peng Fan | d5c3183 | 2023-06-15 18:09:05 +0800 | [diff] [blame] | 478 | msg.version = ELE_VERSION; |
| 479 | msg.tag = ELE_CMD_TAG; |
Ye Li | 395bfd4 | 2023-01-30 18:39:50 +0800 | [diff] [blame] | 480 | msg.size = 1; |
Ye Li | ebb2be5 | 2023-01-30 18:39:53 +0800 | [diff] [blame] | 481 | msg.command = ELE_GET_EVENTS_REQ; |
Ye Li | 395bfd4 | 2023-01-30 18:39:50 +0800 | [diff] [blame] | 482 | |
| 483 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 484 | if (ret) |
| 485 | printf("Error: %s: ret %d, response 0x%x\n", |
| 486 | __func__, ret, msg.data[0]); |
| 487 | |
| 488 | if (response) |
| 489 | *response = msg.data[0]; |
| 490 | |
| 491 | if (!ret) { |
| 492 | actual_events = msg.data[1] & 0xffff; |
| 493 | if (*events_cnt < actual_events) |
| 494 | actual_events = *events_cnt; |
| 495 | |
| 496 | for (; i < actual_events; i++) |
| 497 | events[i] = msg.data[i + 2]; |
| 498 | |
| 499 | *events_cnt = actual_events; |
| 500 | } |
| 501 | |
| 502 | return ret; |
| 503 | } |
Peng Fan | c88036d | 2023-06-15 18:09:08 +0800 | [diff] [blame] | 504 | |
Peng Fan | aa70b85 | 2023-06-15 18:09:14 +0800 | [diff] [blame] | 505 | int ele_start_rng(void) |
| 506 | { |
| 507 | struct udevice *dev = gd->arch.ele_dev; |
| 508 | int size = sizeof(struct ele_msg); |
| 509 | struct ele_msg msg; |
| 510 | int ret; |
| 511 | |
| 512 | if (!dev) { |
| 513 | printf("ele dev is not initialized\n"); |
| 514 | return -ENODEV; |
| 515 | } |
| 516 | |
| 517 | msg.version = ELE_VERSION; |
| 518 | msg.tag = ELE_CMD_TAG; |
| 519 | msg.size = 1; |
| 520 | msg.command = ELE_START_RNG; |
| 521 | |
| 522 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 523 | if (ret) |
| 524 | printf("Error: %s: ret %d, response 0x%x\n", |
| 525 | __func__, ret, msg.data[0]); |
| 526 | |
| 527 | return ret; |
| 528 | } |
| 529 | |
Mathieu Othacehe | 8df8e59 | 2024-03-21 08:19:53 +0100 | [diff] [blame] | 530 | int ele_commit(u16 fuse_id, u32 *response, u32 *info_type) |
| 531 | { |
| 532 | struct udevice *dev = gd->arch.ele_dev; |
| 533 | int size = sizeof(struct ele_msg); |
| 534 | struct ele_msg msg; |
| 535 | int ret = 0; |
| 536 | |
| 537 | if (!dev) { |
| 538 | printf("ele dev is not initialized\n"); |
| 539 | return -ENODEV; |
| 540 | } |
| 541 | |
| 542 | msg.version = ELE_VERSION; |
| 543 | msg.tag = ELE_CMD_TAG; |
| 544 | msg.size = 2; |
| 545 | msg.command = ELE_COMMIT_REQ; |
| 546 | msg.data[0] = fuse_id; |
| 547 | |
| 548 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 549 | if (ret) |
| 550 | printf("Error: %s: ret %d, fuse_id 0x%x, response 0x%x\n", |
| 551 | __func__, ret, fuse_id, msg.data[0]); |
| 552 | |
| 553 | if (response) |
| 554 | *response = msg.data[0]; |
| 555 | |
| 556 | if (info_type) |
| 557 | *info_type = msg.data[1]; |
| 558 | |
| 559 | return ret; |
| 560 | } |
| 561 | |
Peng Fan | c88036d | 2023-06-15 18:09:08 +0800 | [diff] [blame] | 562 | int ele_write_secure_fuse(ulong signed_msg_blk, u32 *response) |
| 563 | { |
| 564 | struct udevice *dev = gd->arch.ele_dev; |
| 565 | int size = sizeof(struct ele_msg); |
| 566 | struct ele_msg msg; |
| 567 | int ret; |
| 568 | |
| 569 | if (!dev) { |
| 570 | printf("ele dev is not initialized\n"); |
| 571 | return -ENODEV; |
| 572 | } |
| 573 | |
| 574 | msg.version = ELE_VERSION; |
| 575 | msg.tag = ELE_CMD_TAG; |
| 576 | msg.size = 3; |
| 577 | msg.command = ELE_WRITE_SECURE_FUSE_REQ; |
| 578 | |
| 579 | msg.data[0] = upper_32_bits(signed_msg_blk); |
| 580 | msg.data[1] = lower_32_bits(signed_msg_blk); |
| 581 | |
| 582 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 583 | if (ret) |
| 584 | printf("Error: %s: ret %d, response 0x%x, failed fuse row index %u\n", |
| 585 | __func__, ret, msg.data[0], msg.data[1]); |
| 586 | |
| 587 | if (response) |
| 588 | *response = msg.data[0]; |
| 589 | |
| 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | int ele_return_lifecycle_update(ulong signed_msg_blk, u32 *response) |
| 594 | { |
| 595 | struct udevice *dev = gd->arch.ele_dev; |
| 596 | int size = sizeof(struct ele_msg); |
| 597 | struct ele_msg msg; |
| 598 | int ret; |
| 599 | |
| 600 | if (!dev) { |
| 601 | printf("ele dev is not initialized\n"); |
| 602 | return -ENODEV; |
| 603 | } |
| 604 | |
| 605 | msg.version = ELE_VERSION; |
| 606 | msg.tag = ELE_CMD_TAG; |
| 607 | msg.size = 3; |
| 608 | msg.command = ELE_RET_LIFECYCLE_UP_REQ; |
| 609 | |
| 610 | msg.data[0] = upper_32_bits(signed_msg_blk); |
| 611 | msg.data[1] = lower_32_bits(signed_msg_blk); |
| 612 | |
| 613 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 614 | if (ret) |
| 615 | printf("Error: %s: ret %d, response 0x%x, failed fuse row index %u\n", |
| 616 | __func__, ret, msg.data[0], msg.data[1]); |
| 617 | |
| 618 | if (response) |
| 619 | *response = msg.data[0]; |
| 620 | |
| 621 | return ret; |
| 622 | } |
Peng Fan | 16426c8 | 2023-06-15 18:09:09 +0800 | [diff] [blame] | 623 | |
| 624 | int ele_generate_dek_blob(u32 key_id, u32 src_paddr, u32 dst_paddr, u32 max_output_size) |
| 625 | { |
| 626 | struct udevice *dev = gd->arch.ele_dev; |
| 627 | int size = sizeof(struct ele_msg); |
| 628 | struct ele_msg msg; |
| 629 | int ret; |
| 630 | |
| 631 | if (!dev) { |
| 632 | printf("ele dev is not initialized\n"); |
| 633 | return -ENODEV; |
| 634 | } |
| 635 | |
| 636 | msg.version = ELE_VERSION; |
| 637 | msg.tag = ELE_CMD_TAG; |
| 638 | msg.size = 8; |
| 639 | msg.command = ELE_GENERATE_DEK_BLOB; |
| 640 | msg.data[0] = key_id; |
| 641 | msg.data[1] = 0x0; |
| 642 | msg.data[2] = src_paddr; |
| 643 | msg.data[3] = 0x0; |
| 644 | msg.data[4] = dst_paddr; |
| 645 | msg.data[5] = max_output_size; |
| 646 | msg.data[6] = compute_crc(&msg); |
| 647 | |
| 648 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 649 | if (ret) |
| 650 | printf("Error: %s: ret 0x%x, response 0x%x\n", |
| 651 | __func__, ret, msg.data[0]); |
| 652 | |
| 653 | return ret; |
| 654 | } |