blob: 8a14cf6aa922c79847db6a75239c0a0f6a25707f [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
7#include <common.h>
8#include <hang.h>
9#include <malloc.h>
10#include <asm/io.h>
11#include <dm.h>
Peng Fand5c31832023-06-15 18:09:05 +080012#include <asm/mach-imx/ele_api.h>
Ye Li0db17f42021-08-07 16:00:41 +080013#include <misc.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
Peng Fan16426c82023-06-15 18:09:09 +080017static 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 Fand5c31832023-06-15 18:09:05 +080029int ele_release_rdc(u8 core_id, u8 xrdc, u32 *response)
Ye Li0db17f42021-08-07 16:00:41 +080030{
Peng Fand5c31832023-06-15 18:09:05 +080031 struct udevice *dev = gd->arch.ele_dev;
32 int size = sizeof(struct ele_msg);
33 struct ele_msg msg;
Ye Li0db17f42021-08-07 16:00:41 +080034 int ret;
35
36 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +080037 printf("ele dev is not initialized\n");
Ye Li0db17f42021-08-07 16:00:41 +080038 return -ENODEV;
39 }
40
Peng Fand5c31832023-06-15 18:09:05 +080041 msg.version = ELE_VERSION;
42 msg.tag = ELE_CMD_TAG;
Ye Li0db17f42021-08-07 16:00:41 +080043 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +080044 msg.command = ELE_RELEASE_RDC_REQ;
Ye Lid4b3ba32022-07-26 16:40:51 +080045 switch (xrdc) {
46 case 0:
Ye Liacc9afe2021-08-07 16:00:53 +080047 msg.data[0] = (0x74 << 8) | core_id;
Ye Lid4b3ba32022-07-26 16:40:51 +080048 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 Li0db17f42021-08-07 16:00:41 +080062
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 Lia61f2672021-08-07 16:00:52 +080068 if (response)
69 *response = msg.data[0];
70
71 return ret;
72}
73
Peng Fand5c31832023-06-15 18:09:05 +080074int ele_auth_oem_ctnr(ulong ctnr_addr, u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +080075{
Peng Fand5c31832023-06-15 18:09:05 +080076 struct udevice *dev = gd->arch.ele_dev;
77 int size = sizeof(struct ele_msg);
78 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +080079 int ret;
80
81 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +080082 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +080083 return -ENODEV;
84 }
85
Peng Fand5c31832023-06-15 18:09:05 +080086 msg.version = ELE_VERSION;
87 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +080088 msg.size = 3;
Ye Liebb2be52023-01-30 18:39:53 +080089 msg.command = ELE_OEM_CNTN_AUTH_REQ;
Ye Lia61f2672021-08-07 16:00:52 +080090 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 Fand5c31832023-06-15 18:09:05 +0800104int ele_release_container(u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +0800105{
Peng Fand5c31832023-06-15 18:09:05 +0800106 struct udevice *dev = gd->arch.ele_dev;
107 int size = sizeof(struct ele_msg);
108 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +0800109 int ret;
110
111 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800112 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +0800113 return -ENODEV;
114 }
115
Peng Fand5c31832023-06-15 18:09:05 +0800116 msg.version = ELE_VERSION;
117 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +0800118 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800119 msg.command = ELE_RELEASE_CONTAINER_REQ;
Ye Lia61f2672021-08-07 16:00:52 +0800120
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 Fand5c31832023-06-15 18:09:05 +0800132int ele_verify_image(u32 img_id, u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +0800133{
Peng Fand5c31832023-06-15 18:09:05 +0800134 struct udevice *dev = gd->arch.ele_dev;
135 int size = sizeof(struct ele_msg);
136 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +0800137 int ret;
138
139 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800140 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +0800141 return -ENODEV;
142 }
143
Peng Fand5c31832023-06-15 18:09:05 +0800144 msg.version = ELE_VERSION;
145 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +0800146 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800147 msg.command = ELE_VERIFY_IMAGE_REQ;
Ye Lia61f2672021-08-07 16:00:52 +0800148 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 Fand5c31832023-06-15 18:09:05 +0800161int ele_forward_lifecycle(u16 life_cycle, u32 *response)
Ye Lia61f2672021-08-07 16:00:52 +0800162{
Peng Fand5c31832023-06-15 18:09:05 +0800163 struct udevice *dev = gd->arch.ele_dev;
164 int size = sizeof(struct ele_msg);
165 struct ele_msg msg;
Ye Lia61f2672021-08-07 16:00:52 +0800166 int ret;
167
168 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800169 printf("ele dev is not initialized\n");
Ye Lia61f2672021-08-07 16:00:52 +0800170 return -ENODEV;
171 }
172
Peng Fand5c31832023-06-15 18:09:05 +0800173 msg.version = ELE_VERSION;
174 msg.tag = ELE_CMD_TAG;
Ye Lia61f2672021-08-07 16:00:52 +0800175 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800176 msg.command = ELE_FWD_LIFECYCLE_UP_REQ;
Ye Lia61f2672021-08-07 16:00:52 +0800177 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 Li0db17f42021-08-07 16:00:41 +0800187 return ret;
188}
Ye Lif80a41b2021-08-07 16:00:54 +0800189
Peng Fand5c31832023-06-15 18:09:05 +0800190int ele_read_common_fuse(u16 fuse_id, u32 *fuse_words, u32 fuse_num, u32 *response)
Ye Lif80a41b2021-08-07 16:00:54 +0800191{
Peng Fand5c31832023-06-15 18:09:05 +0800192 struct udevice *dev = gd->arch.ele_dev;
193 int size = sizeof(struct ele_msg);
194 struct ele_msg msg;
Ye Lif80a41b2021-08-07 16:00:54 +0800195 int ret;
196
197 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800198 printf("ele dev is not initialized\n");
Ye Lif80a41b2021-08-07 16:00:54 +0800199 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 Fand5c31832023-06-15 18:09:05 +0800213 msg.version = ELE_VERSION;
214 msg.tag = ELE_CMD_TAG;
Ye Lif80a41b2021-08-07 16:00:54 +0800215 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800216 msg.command = ELE_READ_FUSE_REQ;
Ye Lif80a41b2021-08-07 16:00:54 +0800217 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 Fand5c31832023-06-15 18:09:05 +0800238int ele_write_fuse(u16 fuse_id, u32 fuse_val, bool lock, u32 *response)
Ye Lif80a41b2021-08-07 16:00:54 +0800239{
Peng Fand5c31832023-06-15 18:09:05 +0800240 struct udevice *dev = gd->arch.ele_dev;
241 int size = sizeof(struct ele_msg);
242 struct ele_msg msg;
Ye Lif80a41b2021-08-07 16:00:54 +0800243 int ret;
244
245 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800246 printf("ele dev is not initialized\n");
Ye Lif80a41b2021-08-07 16:00:54 +0800247 return -ENODEV;
248 }
249
Peng Fand5c31832023-06-15 18:09:05 +0800250 msg.version = ELE_VERSION;
251 msg.tag = ELE_CMD_TAG;
Ye Lif80a41b2021-08-07 16:00:54 +0800252 msg.size = 3;
Ye Liebb2be52023-01-30 18:39:53 +0800253 msg.command = ELE_WRITE_FUSE_REQ;
Ye Lif80a41b2021-08-07 16:00:54 +0800254 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 Faure26386ae2022-04-06 14:30:19 +0800270
Peng Fand5c31832023-06-15 18:09:05 +0800271int ele_release_caam(u32 core_did, u32 *response)
Clement Faure26386ae2022-04-06 14:30:19 +0800272{
Peng Fand5c31832023-06-15 18:09:05 +0800273 struct udevice *dev = gd->arch.ele_dev;
274 int size = sizeof(struct ele_msg);
275 struct ele_msg msg;
Clement Faure26386ae2022-04-06 14:30:19 +0800276 int ret;
277
278 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800279 printf("ele dev is not initialized\n");
Clement Faure26386ae2022-04-06 14:30:19 +0800280 return -ENODEV;
281 }
282
Peng Fand5c31832023-06-15 18:09:05 +0800283 msg.version = ELE_VERSION;
284 msg.tag = ELE_CMD_TAG;
Clement Faure26386ae2022-04-06 14:30:19 +0800285 msg.size = 2;
Ye Liebb2be52023-01-30 18:39:53 +0800286 msg.command = ELE_RELEASE_CAAM_REQ;
Clement Faure26386ae2022-04-06 14:30:19 +0800287 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 Li0a917da2022-04-06 14:30:20 +0800299
Peng Fand5c31832023-06-15 18:09:05 +0800300int ele_get_fw_version(u32 *fw_version, u32 *sha1, u32 *response)
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530301{
Peng Fand5c31832023-06-15 18:09:05 +0800302 struct udevice *dev = gd->arch.ele_dev;
303 int size = sizeof(struct ele_msg);
304 struct ele_msg msg;
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530305 int ret;
306
307 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800308 printf("ele dev is not initialized\n");
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530309 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 Fand5c31832023-06-15 18:09:05 +0800322 msg.version = ELE_VERSION;
323 msg.tag = ELE_CMD_TAG;
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530324 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800325 msg.command = ELE_GET_FW_VERSION_REQ;
Gaurav Jain580cc7b2022-05-11 14:07:55 +0530326
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 Fand5c31832023-06-15 18:09:05 +0800341int ele_dump_buffer(u32 *buffer, u32 buffer_length)
Ye Li0a917da2022-04-06 14:30:20 +0800342{
Peng Fand5c31832023-06-15 18:09:05 +0800343 struct udevice *dev = gd->arch.ele_dev;
344 int size = sizeof(struct ele_msg);
345 struct ele_msg msg;
Ye Li0a917da2022-04-06 14:30:20 +0800346 int ret, i = 0;
347
348 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800349 printf("ele dev is not initialized\n");
Ye Li0a917da2022-04-06 14:30:20 +0800350 return -ENODEV;
351 }
352
Peng Fand5c31832023-06-15 18:09:05 +0800353 msg.version = ELE_VERSION;
354 msg.tag = ELE_CMD_TAG;
Ye Li0a917da2022-04-06 14:30:20 +0800355 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800356 msg.command = ELE_DUMP_DEBUG_BUFFER_REQ;
Ye Li0a917da2022-04-06 14:30:20 +0800357
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 Fancffe2b92022-07-26 16:40:52 +0800374
Peng Fand5c31832023-06-15 18:09:05 +0800375int ele_get_info(struct ele_get_info_data *info, u32 *response)
Peng Fancffe2b92022-07-26 16:40:52 +0800376{
Peng Fand5c31832023-06-15 18:09:05 +0800377 struct udevice *dev = gd->arch.ele_dev;
378 int size = sizeof(struct ele_msg);
379 struct ele_msg msg;
Peng Fancffe2b92022-07-26 16:40:52 +0800380 int ret;
381
382 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800383 printf("ele dev is not initialized\n");
Peng Fancffe2b92022-07-26 16:40:52 +0800384 return -ENODEV;
385 }
386
Peng Fand5c31832023-06-15 18:09:05 +0800387 msg.version = ELE_VERSION;
388 msg.tag = ELE_CMD_TAG;
Peng Fancffe2b92022-07-26 16:40:52 +0800389 msg.size = 4;
Ye Liebb2be52023-01-30 18:39:53 +0800390 msg.command = ELE_GET_INFO_REQ;
Peng Fancffe2b92022-07-26 16:40:52 +0800391 msg.data[0] = upper_32_bits((ulong)info);
392 msg.data[1] = lower_32_bits((ulong)info);
Peng Fand5c31832023-06-15 18:09:05 +0800393 msg.data[2] = sizeof(struct ele_get_info_data);
Peng Fancffe2b92022-07-26 16:40:52 +0800394
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 Fand5c31832023-06-15 18:09:05 +0800406int ele_get_fw_status(u32 *status, u32 *response)
Peng Fancffe2b92022-07-26 16:40:52 +0800407{
Peng Fand5c31832023-06-15 18:09:05 +0800408 struct udevice *dev = gd->arch.ele_dev;
409 int size = sizeof(struct ele_msg);
410 struct ele_msg msg;
Peng Fancffe2b92022-07-26 16:40:52 +0800411 int ret;
412
413 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800414 printf("ele dev is not initialized\n");
Peng Fancffe2b92022-07-26 16:40:52 +0800415 return -ENODEV;
416 }
417
Peng Fand5c31832023-06-15 18:09:05 +0800418 msg.version = ELE_VERSION;
419 msg.tag = ELE_CMD_TAG;
Peng Fancffe2b92022-07-26 16:40:52 +0800420 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800421 msg.command = ELE_GET_FW_STATUS_REQ;
Peng Fancffe2b92022-07-26 16:40:52 +0800422
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 Fanf6ff1402022-07-26 16:40:53 +0800435
Peng Fand5c31832023-06-15 18:09:05 +0800436int ele_release_m33_trout(void)
Peng Fanf6ff1402022-07-26 16:40:53 +0800437{
Peng Fand5c31832023-06-15 18:09:05 +0800438 struct udevice *dev = gd->arch.ele_dev;
439 int size = sizeof(struct ele_msg);
440 struct ele_msg msg;
Peng Fanf6ff1402022-07-26 16:40:53 +0800441 int ret;
442
443 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800444 printf("ele dev is not initialized\n");
Peng Fanf6ff1402022-07-26 16:40:53 +0800445 return -ENODEV;
446 }
447
Peng Fand5c31832023-06-15 18:09:05 +0800448 msg.version = ELE_VERSION;
449 msg.tag = ELE_CMD_TAG;
Peng Fanf6ff1402022-07-26 16:40:53 +0800450 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800451 msg.command = ELE_ENABLE_RTC_REQ;
Peng Fanf6ff1402022-07-26 16:40:53 +0800452
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 Li395bfd42023-01-30 18:39:50 +0800460
Peng Fand5c31832023-06-15 18:09:05 +0800461int ele_get_events(u32 *events, u32 *events_cnt, u32 *response)
Ye Li395bfd42023-01-30 18:39:50 +0800462{
Peng Fand5c31832023-06-15 18:09:05 +0800463 struct udevice *dev = gd->arch.ele_dev;
464 int size = sizeof(struct ele_msg);
465 struct ele_msg msg;
Ye Li395bfd42023-01-30 18:39:50 +0800466 int ret, i = 0;
467 u32 actual_events;
468
469 if (!dev) {
Peng Fand5c31832023-06-15 18:09:05 +0800470 printf("ele dev is not initialized\n");
Ye Li395bfd42023-01-30 18:39:50 +0800471 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 Fand5c31832023-06-15 18:09:05 +0800479 msg.version = ELE_VERSION;
480 msg.tag = ELE_CMD_TAG;
Ye Li395bfd42023-01-30 18:39:50 +0800481 msg.size = 1;
Ye Liebb2be52023-01-30 18:39:53 +0800482 msg.command = ELE_GET_EVENTS_REQ;
Ye Li395bfd42023-01-30 18:39:50 +0800483
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 Fanc88036d2023-06-15 18:09:08 +0800505
506int 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
537int 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 Fan16426c82023-06-15 18:09:09 +0800567
568int 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}