blob: 3745504637b3b472151577a70e0a201f3d7b9098 [file] [log] [blame]
Ye Li0db17f42021-08-07 16:00:41 +08001// SPDX-License-Identifier: GPL-2.0
2/*
Peng Fanc88036d2023-06-15 18:09:08 +08003 * Copyright 2020, 2023 NXP
Ye Li0db17f42021-08-07 16:00:41 +08004 *
5 */
6
Ye Li0db17f42021-08-07 16:00:41 +08007#include <hang.h>
8#include <malloc.h>
9#include <asm/io.h>
10#include <dm.h>
Peng Fand5c31832023-06-15 18:09:05 +080011#include <asm/mach-imx/ele_api.h>
Ye Li0db17f42021-08-07 16:00:41 +080012#include <misc.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
Peng Fan16426c82023-06-15 18:09:09 +080016static 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 Fand5c31832023-06-15 18:09:05 +080028int ele_release_rdc(u8 core_id, u8 xrdc, u32 *response)
Ye Li0db17f42021-08-07 16:00:41 +080029{
Peng Fand5c31832023-06-15 18:09:05 +080030 struct udevice *dev = gd->arch.ele_dev;
31 int size = sizeof(struct ele_msg);
32 struct ele_msg msg;
Ye Li0db17f42021-08-07 16:00:41 +080033 int ret;
34
35 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +080036 printf("ele dev is not initialized\n");
Ye Li0db17f42021-08-07 16:00:41 +080037 return -ENODEV;
38 }
39
Peng Fand5c31832023-06-15 18:09:05 +080040 msg.version = ELE_VERSION;
41 msg.tag = ELE_CMD_TAG;
Ye Li0db17f42021-08-07 16:00:41 +080042 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +080043 msg.command = ELE_RELEASE_RDC_REQ;
Ye Lid4b3ba32022-07-26 16:40:51 +080044 switch (xrdc) {
45 case 0:
Ye Liacc9afe2021-08-07 16:00:53 +080046 msg.data[0] = (0x74 << 8) | core_id;
Ye Lid4b3ba32022-07-26 16:40:51 +080047 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 Li0db17f42021-08-07 16:00:41 +080061
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 Lia61f2672021-08-07 16:00:52 +080067 if (response)
68 *response = msg.data[0];
69
70 return ret;
71}
72
Peng Fand5c31832023-06-15 18:09:05 +080073int ele_auth_oem_ctnr(ulong ctnr_addr, u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +080074{
Peng Fand5c31832023-06-15 18:09:05 +080075 struct udevice *dev = gd->arch.ele_dev;
76 int size = sizeof(struct ele_msg);
77 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +080078 int ret;
79
80 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +080081 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +080082 return -ENODEV;
83 }
84
Peng Fand5c31832023-06-15 18:09:05 +080085 msg.version = ELE_VERSION;
86 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +080087 msg.size = 3;
Ye Liebb2be52023-01-30 18:39:53 +080088 msg.command = ELE_OEM_CNTN_AUTH_REQ;
Ye Lia61f2672021-08-07 16:00:52 +080089 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 Fand5c31832023-06-15 18:09:05 +0800103int ele_release_container(u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +0800104{
Peng Fand5c31832023-06-15 18:09:05 +0800105 struct udevice *dev = gd->arch.ele_dev;
106 int size = sizeof(struct ele_msg);
107 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +0800108 int ret;
109
110 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800111 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +0800112 return -ENODEV;
113 }
114
Peng Fand5c31832023-06-15 18:09:05 +0800115 msg.version = ELE_VERSION;
116 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +0800117 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800118 msg.command = ELE_RELEASE_CONTAINER_REQ;
Ye Lia61f2672021-08-07 16:00:52 +0800119
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 Fand5c31832023-06-15 18:09:05 +0800131int ele_verify_image(u32 img_id, u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +0800132{
Peng Fand5c31832023-06-15 18:09:05 +0800133 struct udevice *dev = gd->arch.ele_dev;
134 int size = sizeof(struct ele_msg);
135 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +0800136 int ret;
137
138 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800139 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +0800140 return -ENODEV;
141 }
142
Peng Fand5c31832023-06-15 18:09:05 +0800143 msg.version = ELE_VERSION;
144 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +0800145 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800146 msg.command = ELE_VERIFY_IMAGE_REQ;
Ye Lia61f2672021-08-07 16:00:52 +0800147 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 Fand5c31832023-06-15 18:09:05 +0800160int ele_forward_lifecycle(u16 life_cycle, u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +0800161{
Peng Fand5c31832023-06-15 18:09:05 +0800162 struct udevice *dev = gd->arch.ele_dev;
163 int size = sizeof(struct ele_msg);
164 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +0800165 int ret;
166
167 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800168 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +0800169 return -ENODEV;
170 }
171
Peng Fand5c31832023-06-15 18:09:05 +0800172 msg.version = ELE_VERSION;
173 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +0800174 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800175 msg.command = ELE_FWD_LIFECYCLE_UP_REQ;
Ye Lia61f2672021-08-07 16:00:52 +0800176 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 Li0db17f42021-08-07 16:00:41 +0800186 return ret;
187}
Ye Lif80a41b2021-08-07 16:00:54 +0800188
Peng Fand5c31832023-06-15 18:09:05 +0800189int ele_read_common_fuse(u16 fuse_id, u32 *fuse_words, u32 fuse_num, u32 *response)
Ye Lif80a41b2021-08-07 16:00:54 +0800190{
Peng Fand5c31832023-06-15 18:09:05 +0800191 struct udevice *dev = gd->arch.ele_dev;
192 int size = sizeof(struct ele_msg);
193 struct ele_msg msg;
Ye Lif80a41b2021-08-07 16:00:54 +0800194 int ret;
195
196 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800197 printf("ele dev is not initialized\n");
Ye Lif80a41b2021-08-07 16:00:54 +0800198 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 Fand5c31832023-06-15 18:09:05 +0800212 msg.version = ELE_VERSION;
213 msg.tag = ELE_CMD_TAG;
Ye Lif80a41b2021-08-07 16:00:54 +0800214 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800215 msg.command = ELE_READ_FUSE_REQ;
Ye Lif80a41b2021-08-07 16:00:54 +0800216 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 Fand5c31832023-06-15 18:09:05 +0800237int ele_write_fuse(u16 fuse_id, u32 fuse_val, bool lock, u32 *response)
Ye Lif80a41b2021-08-07 16:00:54 +0800238{
Peng Fand5c31832023-06-15 18:09:05 +0800239 struct udevice *dev = gd->arch.ele_dev;
240 int size = sizeof(struct ele_msg);
241 struct ele_msg msg;
Ye Lif80a41b2021-08-07 16:00:54 +0800242 int ret;
243
244 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800245 printf("ele dev is not initialized\n");
Ye Lif80a41b2021-08-07 16:00:54 +0800246 return -ENODEV;
247 }
248
Peng Fand5c31832023-06-15 18:09:05 +0800249 msg.version = ELE_VERSION;
250 msg.tag = ELE_CMD_TAG;
Ye Lif80a41b2021-08-07 16:00:54 +0800251 msg.size = 3;
Ye Liebb2be52023-01-30 18:39:53 +0800252 msg.command = ELE_WRITE_FUSE_REQ;
Ye Lif80a41b2021-08-07 16:00:54 +0800253 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 Faure26386ae2022-04-06 14:30:19 +0800269
Peng Fand5c31832023-06-15 18:09:05 +0800270int ele_release_caam(u32 core_did, u32 *response)
Clement Faure26386ae2022-04-06 14:30:19 +0800271{
Peng Fand5c31832023-06-15 18:09:05 +0800272 struct udevice *dev = gd->arch.ele_dev;
273 int size = sizeof(struct ele_msg);
274 struct ele_msg msg;
Clement Faure26386ae2022-04-06 14:30:19 +0800275 int ret;
276
277 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800278 printf("ele dev is not initialized\n");
Clement Faure26386ae2022-04-06 14:30:19 +0800279 return -ENODEV;
280 }
281
Peng Fand5c31832023-06-15 18:09:05 +0800282 msg.version = ELE_VERSION;
283 msg.tag = ELE_CMD_TAG;
Clement Faure26386ae2022-04-06 14:30:19 +0800284 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800285 msg.command = ELE_RELEASE_CAAM_REQ;
Clement Faure26386ae2022-04-06 14:30:19 +0800286 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 Li0a917da2022-04-06 14:30:20 +0800298
Peng Fand5c31832023-06-15 18:09:05 +0800299int ele_get_fw_version(u32 *fw_version, u32 *sha1, u32 *response)
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530300{
Peng Fand5c31832023-06-15 18:09:05 +0800301 struct udevice *dev = gd->arch.ele_dev;
302 int size = sizeof(struct ele_msg);
303 struct ele_msg msg;
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530304 int ret;
305
306 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800307 printf("ele dev is not initialized\n");
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530308 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 Fand5c31832023-06-15 18:09:05 +0800321 msg.version = ELE_VERSION;
322 msg.tag = ELE_CMD_TAG;
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530323 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800324 msg.command = ELE_GET_FW_VERSION_REQ;
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530325
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 Fand5c31832023-06-15 18:09:05 +0800340int ele_dump_buffer(u32 *buffer, u32 buffer_length)
Ye Li0a917da2022-04-06 14:30:20 +0800341{
Peng Fand5c31832023-06-15 18:09:05 +0800342 struct udevice *dev = gd->arch.ele_dev;
343 int size = sizeof(struct ele_msg);
344 struct ele_msg msg;
Ye Li0a917da2022-04-06 14:30:20 +0800345 int ret, i = 0;
346
347 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800348 printf("ele dev is not initialized\n");
Ye Li0a917da2022-04-06 14:30:20 +0800349 return -ENODEV;
350 }
351
Peng Fand5c31832023-06-15 18:09:05 +0800352 msg.version = ELE_VERSION;
353 msg.tag = ELE_CMD_TAG;
Ye Li0a917da2022-04-06 14:30:20 +0800354 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800355 msg.command = ELE_DUMP_DEBUG_BUFFER_REQ;
Ye Li0a917da2022-04-06 14:30:20 +0800356
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 Fancffe2b92022-07-26 16:40:52 +0800373
Peng Fand5c31832023-06-15 18:09:05 +0800374int ele_get_info(struct ele_get_info_data *info, u32 *response)
Peng Fancffe2b92022-07-26 16:40:52 +0800375{
Peng Fand5c31832023-06-15 18:09:05 +0800376 struct udevice *dev = gd->arch.ele_dev;
377 int size = sizeof(struct ele_msg);
378 struct ele_msg msg;
Peng Fancffe2b92022-07-26 16:40:52 +0800379 int ret;
380
381 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800382 printf("ele dev is not initialized\n");
Peng Fancffe2b92022-07-26 16:40:52 +0800383 return -ENODEV;
384 }
385
Peng Fand5c31832023-06-15 18:09:05 +0800386 msg.version = ELE_VERSION;
387 msg.tag = ELE_CMD_TAG;
Peng Fancffe2b92022-07-26 16:40:52 +0800388 msg.size = 4;
Ye Liebb2be52023-01-30 18:39:53 +0800389 msg.command = ELE_GET_INFO_REQ;
Peng Fancffe2b92022-07-26 16:40:52 +0800390 msg.data[0] = upper_32_bits((ulong)info);
391 msg.data[1] = lower_32_bits((ulong)info);
Peng Fand5c31832023-06-15 18:09:05 +0800392 msg.data[2] = sizeof(struct ele_get_info_data);
Peng Fancffe2b92022-07-26 16:40:52 +0800393
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 Fand5c31832023-06-15 18:09:05 +0800405int ele_get_fw_status(u32 *status, u32 *response)
Peng Fancffe2b92022-07-26 16:40:52 +0800406{
Peng Fand5c31832023-06-15 18:09:05 +0800407 struct udevice *dev = gd->arch.ele_dev;
408 int size = sizeof(struct ele_msg);
409 struct ele_msg msg;
Peng Fancffe2b92022-07-26 16:40:52 +0800410 int ret;
411
412 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800413 printf("ele dev is not initialized\n");
Peng Fancffe2b92022-07-26 16:40:52 +0800414 return -ENODEV;
415 }
416
Peng Fand5c31832023-06-15 18:09:05 +0800417 msg.version = ELE_VERSION;
418 msg.tag = ELE_CMD_TAG;
Peng Fancffe2b92022-07-26 16:40:52 +0800419 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800420 msg.command = ELE_GET_FW_STATUS_REQ;
Peng Fancffe2b92022-07-26 16:40:52 +0800421
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 Fanf6ff1402022-07-26 16:40:53 +0800434
Peng Fand5c31832023-06-15 18:09:05 +0800435int ele_release_m33_trout(void)
Peng Fanf6ff1402022-07-26 16:40:53 +0800436{
Peng Fand5c31832023-06-15 18:09:05 +0800437 struct udevice *dev = gd->arch.ele_dev;
438 int size = sizeof(struct ele_msg);
439 struct ele_msg msg;
Peng Fanf6ff1402022-07-26 16:40:53 +0800440 int ret;
441
442 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800443 printf("ele dev is not initialized\n");
Peng Fanf6ff1402022-07-26 16:40:53 +0800444 return -ENODEV;
445 }
446
Peng Fand5c31832023-06-15 18:09:05 +0800447 msg.version = ELE_VERSION;
448 msg.tag = ELE_CMD_TAG;
Peng Fanf6ff1402022-07-26 16:40:53 +0800449 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800450 msg.command = ELE_ENABLE_RTC_REQ;
Peng Fanf6ff1402022-07-26 16:40:53 +0800451
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 Li395bfd42023-01-30 18:39:50 +0800459
Peng Fand5c31832023-06-15 18:09:05 +0800460int ele_get_events(u32 *events, u32 *events_cnt, u32 *response)
Ye Li395bfd42023-01-30 18:39:50 +0800461{
Peng Fand5c31832023-06-15 18:09:05 +0800462 struct udevice *dev = gd->arch.ele_dev;
463 int size = sizeof(struct ele_msg);
464 struct ele_msg msg;
Ye Li395bfd42023-01-30 18:39:50 +0800465 int ret, i = 0;
466 u32 actual_events;
467
468 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800469 printf("ele dev is not initialized\n");
Ye Li395bfd42023-01-30 18:39:50 +0800470 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 Fand5c31832023-06-15 18:09:05 +0800478 msg.version = ELE_VERSION;
479 msg.tag = ELE_CMD_TAG;
Ye Li395bfd42023-01-30 18:39:50 +0800480 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800481 msg.command = ELE_GET_EVENTS_REQ;
Ye Li395bfd42023-01-30 18:39:50 +0800482
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 Fanc88036d2023-06-15 18:09:08 +0800504
Peng Fanaa70b852023-06-15 18:09:14 +0800505int 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 Othacehe8df8e592024-03-21 08:19:53 +0100530int 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 Fanc88036d2023-06-15 18:09:08 +0800562int 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
593int 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 Fan16426c82023-06-15 18:09:09 +0800623
624int 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}