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