blob: 591d71b096a8d4293c91d4b58e55d63da078d274 [file] [log] [blame]
Peng Fan55486382018-10-18 14:28:12 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2018 NXP
4 *
5 * Peng Fan <peng.fan@nxp.com>
6 */
7
Simon Glassf11478f2019-12-28 10:45:07 -07008#include <hang.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Peng Fan55486382018-10-18 14:28:12 +020011#include <asm/io.h>
12#include <dm.h>
Peng Fan2e0644a2023-04-28 12:08:09 +080013#include <firmware/imx/sci/sci.h>
Peng Fan55486382018-10-18 14:28:12 +020014#include <misc.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Peng Fand4191db2019-09-23 10:12:31 +000018#define B2U8(X) (((X) != SC_FALSE) ? (u8)(0x01U) : (u8)(0x00U))
19
Peng Fan55486382018-10-18 14:28:12 +020020/* CLK and PM */
21int sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
22 sc_pm_clock_rate_t *rate)
23{
24 struct udevice *dev = gd->arch.scu_dev;
25 int size = sizeof(struct sc_rpc_msg_s);
26 struct sc_rpc_msg_s msg;
27 int ret;
28
29 RPC_VER(&msg) = SC_RPC_VERSION;
30 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
31 RPC_FUNC(&msg) = (u8)PM_FUNC_SET_CLOCK_RATE;
32 RPC_U32(&msg, 0U) = *(u32 *)rate;
33 RPC_U16(&msg, 4U) = (u16)resource;
34 RPC_U8(&msg, 6U) = (u8)clk;
35 RPC_SIZE(&msg) = 3U;
36
37 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
38 if (ret)
39 printf("%s: rate:%u resource:%u: clk:%u res:%d\n",
40 __func__, *rate, resource, clk, RPC_R8(&msg));
41
42 *rate = RPC_U32(&msg, 0U);
43
44 return ret;
45}
46
47int sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
48 sc_pm_clock_rate_t *rate)
49{
50 struct udevice *dev = gd->arch.scu_dev;
51 int size = sizeof(struct sc_rpc_msg_s);
52 struct sc_rpc_msg_s msg;
53 int ret;
54
55 RPC_VER(&msg) = SC_RPC_VERSION;
56 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
57 RPC_FUNC(&msg) = (u8)PM_FUNC_GET_CLOCK_RATE;
58 RPC_U16(&msg, 0U) = (u16)resource;
59 RPC_U8(&msg, 2U) = (u8)clk;
60 RPC_SIZE(&msg) = 2U;
61
62 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
63 if (ret) {
64 printf("%s: resource:%d clk:%d: res:%d\n",
65 __func__, resource, clk, RPC_R8(&msg));
66 return ret;
67 }
68
69 if (rate)
70 *rate = RPC_U32(&msg, 0U);
71
72 return 0;
73}
74
75int sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource, sc_pm_clk_t clk,
76 sc_bool_t enable, sc_bool_t autog)
77{
78 struct udevice *dev = gd->arch.scu_dev;
79 int size = sizeof(struct sc_rpc_msg_s);
80 struct sc_rpc_msg_s msg;
81 int ret;
82
83 RPC_VER(&msg) = SC_RPC_VERSION;
84 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
85 RPC_FUNC(&msg) = (u8)PM_FUNC_CLOCK_ENABLE;
86 RPC_U16(&msg, 0U) = (u16)resource;
87 RPC_U8(&msg, 2U) = (u8)clk;
88 RPC_U8(&msg, 3U) = (u8)enable;
89 RPC_U8(&msg, 4U) = (u8)autog;
90 RPC_SIZE(&msg) = 3U;
91
92 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
93 if (ret)
94 printf("%s: resource:%d clk:%d: enable:%d autog: %d, res:%d\n",
95 __func__, resource, clk, enable, autog, RPC_R8(&msg));
96
97 return ret;
98}
99
Peng Fand4191db2019-09-23 10:12:31 +0000100int sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource,
101 sc_pm_clk_t clk, sc_pm_clk_parent_t parent)
102{
103 struct udevice *dev = gd->arch.scu_dev;
104 int size = sizeof(struct sc_rpc_msg_s);
105 struct sc_rpc_msg_s msg;
106 int ret;
107
108 RPC_VER(&msg) = SC_RPC_VERSION;
109 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
110 RPC_FUNC(&msg) = (u8)PM_FUNC_SET_CLOCK_PARENT;
111 RPC_U16(&msg, 0U) = (u16)resource;
112 RPC_U8(&msg, 2U) = (u8)clk;
113 RPC_U8(&msg, 3U) = (u8)parent;
114 RPC_SIZE(&msg) = 2U;
115
116 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
117 if (ret)
118 printf("%s: resource:%d clk:%d: parent clk: %d, res:%d\n",
119 __func__, resource, clk, parent, RPC_R8(&msg));
120
121 return ret;
122}
123
Peng Fan55486382018-10-18 14:28:12 +0200124int sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
125 sc_pm_power_mode_t mode)
126{
127 struct udevice *dev = gd->arch.scu_dev;
128 int size = sizeof(struct sc_rpc_msg_s);
129 struct sc_rpc_msg_s msg;
130 int ret;
131
132 if (!dev)
133 hang();
134
135 RPC_VER(&msg) = SC_RPC_VERSION;
136 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
137 RPC_FUNC(&msg) = (u8)PM_FUNC_SET_RESOURCE_POWER_MODE;
138 RPC_U16(&msg, 0U) = (u16)resource;
139 RPC_U8(&msg, 2U) = (u8)mode;
140 RPC_SIZE(&msg) = 2U;
141
142 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
143 if (ret)
144 printf("%s: resource:%d mode:%d: res:%d\n",
145 __func__, resource, mode, RPC_R8(&msg));
146
147 return ret;
148}
149
Peng Fan098d3e62019-08-26 08:12:16 +0000150sc_bool_t sc_pm_is_partition_started(sc_ipc_t ipc, sc_rm_pt_t pt)
151{
152 struct udevice *dev = gd->arch.scu_dev;
153 int size = sizeof(struct sc_rpc_msg_s);
154 struct sc_rpc_msg_s msg;
155 int ret;
156 u8 result;
157
158 RPC_VER(&msg) = SC_RPC_VERSION;
159 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_PM);
160 RPC_FUNC(&msg) = (u8)(PM_FUNC_IS_PARTITION_STARTED);
161 RPC_U8(&msg, 0U) = (u8)(pt);
162 RPC_SIZE(&msg) = 2U;
163
164 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
165
166 result = RPC_R8(&msg);
167 if (result != 0 && result != 1) {
168 printf("%s: partition:%d res:%d\n",
169 __func__, pt, RPC_R8(&msg));
170 if (ret)
171 printf("%s: partition:%d res:%d\n", __func__, pt,
172 RPC_R8(&msg));
173 }
174 return !!result;
175}
176
Ye Li24b5dae2019-11-13 21:20:43 -0800177int sc_pm_resource_reset(sc_ipc_t ipc, sc_rsrc_t resource)
178{
179 struct udevice *dev = gd->arch.scu_dev;
180 int size = sizeof(struct sc_rpc_msg_s);
181 struct sc_rpc_msg_s msg;
182 int ret;
183
184 RPC_VER(&msg) = SC_RPC_VERSION;
185 RPC_SIZE(&msg) = 2U;
186 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_PM);
187 RPC_FUNC(&msg) = (u8)(PM_FUNC_RESOURCE_RESET);
188
189 RPC_U16(&msg, 0U) = (u16)(resource);
190
191 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
192 if (ret)
193 printf("%s: resource:%d res:%d\n",
194 __func__, resource, RPC_R8(&msg));
195
196 return ret;
197}
198
Peng Fan55486382018-10-18 14:28:12 +0200199/* PAD */
200int sc_pad_set(sc_ipc_t ipc, sc_pad_t pad, u32 val)
201{
202 struct udevice *dev = gd->arch.scu_dev;
203 int size = sizeof(struct sc_rpc_msg_s);
204 struct sc_rpc_msg_s msg;
205 int ret;
206
207 if (!dev)
208 hang();
209
210 RPC_VER(&msg) = SC_RPC_VERSION;
211 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PAD;
212 RPC_FUNC(&msg) = (u8)PAD_FUNC_SET;
213 RPC_U32(&msg, 0U) = (u32)val;
214 RPC_U16(&msg, 4U) = (u16)pad;
215 RPC_SIZE(&msg) = 3U;
216
217 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
218 if (ret)
219 printf("%s: val:%d pad:%d: res:%d\n",
220 __func__, val, pad, RPC_R8(&msg));
221
222 return ret;
223}
224
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +0200225int sc_pad_get(sc_ipc_t ipc, sc_pad_t pad, u32 *val)
226{
227 struct udevice *dev = gd->arch.scu_dev;
228 int size = sizeof(struct sc_rpc_msg_s);
229 struct sc_rpc_msg_s msg;
230 int ret;
231
232 if (!dev)
233 hang();
234
235 RPC_VER(&msg) = SC_RPC_VERSION;
236 RPC_SIZE(&msg) = 2U;
237 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_PAD);
238 RPC_FUNC(&msg) = (u8)(PAD_FUNC_GET);
239
240 RPC_U16(&msg, 0U) = (u16)(pad);
241
242 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
243 if (ret)
244 printf("%s: pad:%d: res:%d\n",
245 __func__, pad, RPC_R8(&msg));
246
247 if (val)
248 *val = (u32)RPC_U32(&msg, 0U);
249
250 return ret;
251}
252
Peng Fan55486382018-10-18 14:28:12 +0200253/* MISC */
Peng Fand4191db2019-09-23 10:12:31 +0000254int sc_misc_set_control(sc_ipc_t ipc, sc_rsrc_t resource,
255 sc_ctrl_t ctrl, u32 val)
256{
257 struct udevice *dev = gd->arch.scu_dev;
258 int size = sizeof(struct sc_rpc_msg_s);
259 struct sc_rpc_msg_s msg;
260 int ret;
261
262 if (!dev)
263 hang();
264
265 RPC_VER(&msg) = SC_RPC_VERSION;
266 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
267 RPC_FUNC(&msg) = (u8)MISC_FUNC_SET_CONTROL;
268 RPC_U32(&msg, 0U) = (u32)ctrl;
269 RPC_U32(&msg, 4U) = (u32)val;
270 RPC_U16(&msg, 8U) = (u16)resource;
271 RPC_SIZE(&msg) = 4U;
272
273 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
274 if (ret)
275 printf("%s: ctrl:%d resource:%d: res:%d\n",
276 __func__, ctrl, resource, RPC_R8(&msg));
277
278 return ret;
279}
280
Peng Fan55486382018-10-18 14:28:12 +0200281int sc_misc_get_control(sc_ipc_t ipc, sc_rsrc_t resource, sc_ctrl_t ctrl,
282 u32 *val)
283{
284 struct udevice *dev = gd->arch.scu_dev;
285 int size = sizeof(struct sc_rpc_msg_s);
286 struct sc_rpc_msg_s msg;
287 int ret;
288
289 if (!dev)
290 hang();
291
292 RPC_VER(&msg) = SC_RPC_VERSION;
293 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
294 RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_CONTROL;
295 RPC_U32(&msg, 0U) = (u32)ctrl;
296 RPC_U16(&msg, 4U) = (u16)resource;
297 RPC_SIZE(&msg) = 3U;
298
299 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
300 if (ret)
301 printf("%s: ctrl:%d resource:%d: res:%d\n",
302 __func__, ctrl, resource, RPC_R8(&msg));
303
Peng Fan927a3dc2018-12-15 12:19:49 +0000304 if (val)
Peng Fan55486382018-10-18 14:28:12 +0200305 *val = RPC_U32(&msg, 0U);
306
307 return ret;
308}
309
Peng Fand4191db2019-09-23 10:12:31 +0000310int sc_rm_set_master_sid(sc_ipc_t ipc, sc_rsrc_t resource, sc_rm_sid_t sid)
311{
312 struct udevice *dev = gd->arch.scu_dev;
313 struct sc_rpc_msg_s msg;
314 int size = sizeof(struct sc_rpc_msg_s);
315 int ret;
316
317 RPC_VER(&msg) = SC_RPC_VERSION;
318 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
319 RPC_FUNC(&msg) = (u8)RM_FUNC_SET_MASTER_SID;
320 RPC_U16(&msg, 0U) = (u16)resource;
321 RPC_U16(&msg, 2U) = (u16)sid;
322 RPC_SIZE(&msg) = 2U;
323
324 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
325 if (ret)
326 printf("%s: resource:%d sid:%d: res:%d\n",
327 __func__, resource, sid, RPC_R8(&msg));
328
329 return ret;
330}
331
Peng Fan55486382018-10-18 14:28:12 +0200332void sc_misc_get_boot_dev(sc_ipc_t ipc, sc_rsrc_t *boot_dev)
333{
334 struct udevice *dev = gd->arch.scu_dev;
335 int size = sizeof(struct sc_rpc_msg_s);
336 struct sc_rpc_msg_s msg;
337 int ret;
338
339 if (!dev)
340 hang();
341
342 RPC_VER(&msg) = SC_RPC_VERSION;
343 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
344 RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_BOOT_DEV;
345 RPC_SIZE(&msg) = 1U;
346
347 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
348 if (ret)
349 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
350
Peng Fan927a3dc2018-12-15 12:19:49 +0000351 if (boot_dev)
Peng Fan55486382018-10-18 14:28:12 +0200352 *boot_dev = RPC_U16(&msg, 0U);
353}
354
355void sc_misc_boot_status(sc_ipc_t ipc, sc_misc_boot_status_t status)
356{
357 struct udevice *dev = gd->arch.scu_dev;
358 int size = sizeof(struct sc_rpc_msg_s);
359 struct sc_rpc_msg_s msg;
360 int ret;
361
362 if (!dev)
363 hang();
364
365 RPC_VER(&msg) = SC_RPC_VERSION;
366 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
367 RPC_FUNC(&msg) = (u8)MISC_FUNC_BOOT_STATUS;
368 RPC_U8(&msg, 0U) = (u8)status;
369 RPC_SIZE(&msg) = 2U;
370
371 ret = misc_call(dev, SC_TRUE, &msg, size, &msg, size);
372 if (ret)
373 printf("%s: status:%d res:%d\n",
374 __func__, status, RPC_R8(&msg));
375}
376
Ye Lic9c35a42020-06-09 03:34:42 -0700377int sc_misc_get_boot_container(sc_ipc_t ipc, u8 *idx)
378{
379 struct udevice *dev = gd->arch.scu_dev;
380 int size = sizeof(struct sc_rpc_msg_s);
381 struct sc_rpc_msg_s msg;
382 int ret;
383
384 if (!dev)
385 hang();
386
387 RPC_VER(&msg) = SC_RPC_VERSION;
388 RPC_SIZE(&msg) = 1U;
389 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
390 RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_BOOT_CONTAINER;
391
392 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
393 if (ret < 0)
394 return ret;
395
396 if (idx)
397 *idx = (u8)RPC_U8(&msg, 0U);
398
399 return 0;
400}
401
Peng Fan55486382018-10-18 14:28:12 +0200402void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit)
403{
404 struct udevice *dev = gd->arch.scu_dev;
405 int size = sizeof(struct sc_rpc_msg_s);
406 struct sc_rpc_msg_s msg;
407 int ret;
408
409 if (!dev)
410 hang();
411
412 RPC_VER(&msg) = SC_RPC_VERSION;
413 RPC_SVC(&msg) = SC_RPC_SVC_MISC;
414 RPC_FUNC(&msg) = MISC_FUNC_BUILD_INFO;
415 RPC_SIZE(&msg) = 1;
416
417 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
418 if (ret < 0) {
419 printf("%s: err: %d\n", __func__, ret);
420 return;
421 }
422
423 if (build)
424 *build = RPC_U32(&msg, 0);
425 if (commit)
426 *commit = RPC_U32(&msg, 4);
427}
428
429int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val)
430{
431 struct udevice *dev = gd->arch.scu_dev;
432 int size = sizeof(struct sc_rpc_msg_s);
433 struct sc_rpc_msg_s msg;
434 int ret;
435
436 if (!dev)
437 hang();
438
439 RPC_VER(&msg) = SC_RPC_VERSION;
440 RPC_SVC(&msg) = SC_RPC_SVC_MISC;
441 RPC_FUNC(&msg) = MISC_FUNC_OTP_FUSE_READ;
442 RPC_U32(&msg, 0) = word;
443 RPC_SIZE(&msg) = 2;
444
445 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
446 if (ret < 0)
447 return ret;
448
449 if (val)
450 *val = RPC_U32(&msg, 0U);
451
452 return 0;
453}
454
Peng Fanba44e012019-05-05 13:23:51 +0000455int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp,
456 s16 *celsius, s8 *tenths)
457{
458 struct udevice *dev = gd->arch.scu_dev;
459 int size = sizeof(struct sc_rpc_msg_s);
460 struct sc_rpc_msg_s msg;
461 int ret;
462
463 RPC_VER(&msg) = SC_RPC_VERSION;
464 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
465 RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_TEMP;
466 RPC_U16(&msg, 0U) = (u16)resource;
467 RPC_U8(&msg, 2U) = (u8)temp;
468 RPC_SIZE(&msg) = 2U;
469
470 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
471 if (ret < 0)
472 return ret;
473
474 if (celsius)
475 *celsius = RPC_I16(&msg, 0U);
476
477 if (tenths)
478 *tenths = RPC_I8(&msg, 2U);
479
480 return 0;
481}
482
Peng Fane89a3912023-06-15 18:09:04 +0800483void sc_misc_get_button_status(sc_ipc_t ipc, sc_bool_t *status)
484{
485 struct sc_rpc_msg_s msg;
486 struct udevice *dev = gd->arch.scu_dev;
487
488 RPC_VER(&msg) = SC_RPC_VERSION;
489 RPC_SIZE(&msg) = 1U;
490 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_MISC);
491 RPC_FUNC(&msg) = (u8)(MISC_FUNC_GET_BUTTON_STATUS);
492
493 misc_call(dev, SC_FALSE, &msg, 1U, &msg, 1U);
494
495 if (status)
496 *status = (sc_bool_t)(!!(RPC_U8(&msg, 0U)));
497}
498
Peng Fan55486382018-10-18 14:28:12 +0200499/* RM */
500sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr)
501{
502 struct udevice *dev = gd->arch.scu_dev;
503 int size = sizeof(struct sc_rpc_msg_s);
504 struct sc_rpc_msg_s msg;
505 int ret;
506 sc_err_t result;
507
508 if (!dev)
509 hang();
510
511 RPC_VER(&msg) = SC_RPC_VERSION;
512 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
513 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_MEMREG_OWNED;
514 RPC_U8(&msg, 0U) = (u8)mr;
515 RPC_SIZE(&msg) = 2U;
516
517 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
518 result = RPC_R8(&msg);
519
520 if (result != 0 && result != 1) {
521 printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
522 if (ret)
523 printf("%s: mr:%d res:%d\n", __func__, mr,
524 RPC_R8(&msg));
525 }
526
527 return (sc_bool_t)result;
528}
529
Peng Fand4191db2019-09-23 10:12:31 +0000530int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
531 sc_faddr_t addr_end)
Peng Fanb612a302019-08-26 08:12:03 +0000532{
533 struct udevice *dev = gd->arch.scu_dev;
Peng Fand4191db2019-09-23 10:12:31 +0000534 int size = sizeof(struct sc_rpc_msg_s);
Peng Fanb612a302019-08-26 08:12:03 +0000535 struct sc_rpc_msg_s msg;
Peng Fand4191db2019-09-23 10:12:31 +0000536 int ret;
537
538 if (!dev)
539 hang();
540
541 RPC_VER(&msg) = SC_RPC_VERSION;
542 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM);
543 RPC_FUNC(&msg) = (u8)(RM_FUNC_FIND_MEMREG);
544 RPC_U32(&msg, 0U) = (u32)(addr_start >> 32ULL);
545 RPC_U32(&msg, 4U) = (u32)(addr_start);
546 RPC_U32(&msg, 8U) = (u32)(addr_end >> 32ULL);
547 RPC_U32(&msg, 12U) = (u32)(addr_end);
548 RPC_SIZE(&msg) = 5U;
549
550 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
551 if (ret)
552 printf("%s: start:0x%llx, end:0x%llx res:%d\n", __func__, addr_start, addr_end, RPC_R8(&msg));
553
554 if (mr)
555 *mr = RPC_U8(&msg, 0U);
556
557 return ret;
558}
559
560int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr,
561 sc_rm_pt_t pt, sc_rm_perm_t perm)
562{
563 struct udevice *dev = gd->arch.scu_dev;
Peng Fanb612a302019-08-26 08:12:03 +0000564 int size = sizeof(struct sc_rpc_msg_s);
Peng Fand4191db2019-09-23 10:12:31 +0000565 struct sc_rpc_msg_s msg;
Peng Fanb612a302019-08-26 08:12:03 +0000566 int ret;
567
Peng Fand4191db2019-09-23 10:12:31 +0000568 if (!dev)
569 hang();
570
Peng Fanb612a302019-08-26 08:12:03 +0000571 RPC_VER(&msg) = SC_RPC_VERSION;
Peng Fand4191db2019-09-23 10:12:31 +0000572 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM);
573 RPC_FUNC(&msg) = (u8)(RM_FUNC_SET_MEMREG_PERMISSIONS);
574 RPC_U8(&msg, 0U) = (u8)(mr);
575 RPC_U8(&msg, 1U) = (u8)(pt);
576 RPC_U8(&msg, 2U) = (u8)(perm);
Peng Fanb612a302019-08-26 08:12:03 +0000577 RPC_SIZE(&msg) = 2U;
578
579 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
Peng Fand4191db2019-09-23 10:12:31 +0000580 if (ret) {
581 printf("%s: mr:%u, pt:%u, perm:%u, res:%d\n", __func__,
582 mr, pt, perm, RPC_R8(&msg));
583 }
Peng Fanb612a302019-08-26 08:12:03 +0000584
585 return ret;
586}
587
Peng Fan55486382018-10-18 14:28:12 +0200588int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
589 sc_faddr_t *addr_end)
590{
591 struct udevice *dev = gd->arch.scu_dev;
592 int size = sizeof(struct sc_rpc_msg_s);
593 struct sc_rpc_msg_s msg;
594 int ret;
595
596 if (!dev)
597 hang();
598
599 RPC_VER(&msg) = SC_RPC_VERSION;
600 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
601 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_MEMREG_INFO;
602 RPC_U8(&msg, 0U) = (u8)mr;
603 RPC_SIZE(&msg) = 2U;
604
605 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
606 if (ret)
607 printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
608
609 if (addr_start)
610 *addr_start = ((u64)RPC_U32(&msg, 0U) << 32U) |
611 RPC_U32(&msg, 4U);
612
613 if (addr_end)
614 *addr_end = ((u64)RPC_U32(&msg, 8U) << 32U) |
615 RPC_U32(&msg, 12U);
616
617 return ret;
618}
619
620sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource)
621{
622 struct udevice *dev = gd->arch.scu_dev;
623 int size = sizeof(struct sc_rpc_msg_s);
624 struct sc_rpc_msg_s msg;
625 int ret;
626 u8 result;
627
628 if (!dev)
629 hang();
630
631 RPC_VER(&msg) = SC_RPC_VERSION;
632 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
633 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_RESOURCE_OWNED;
634 RPC_U16(&msg, 0U) = (u16)resource;
635 RPC_SIZE(&msg) = 2U;
636
637 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
638 result = RPC_R8(&msg);
639 if (result != 0 && result != 1) {
640 printf("%s: resource:%d res:%d\n",
641 __func__, resource, RPC_R8(&msg));
642 if (ret)
643 printf("%s: res:%d res:%d\n", __func__, resource,
644 RPC_R8(&msg));
645 }
646
647 return !!result;
648}
Peng Fand4191db2019-09-23 10:12:31 +0000649
650int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
651 sc_bool_t isolated, sc_bool_t restricted,
652 sc_bool_t grant, sc_bool_t coherent)
653{
654 struct udevice *dev = gd->arch.scu_dev;
655 struct sc_rpc_msg_s msg;
656 int size = sizeof(struct sc_rpc_msg_s);
657 int ret;
658
659 RPC_VER(&msg) = SC_RPC_VERSION;
660 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
661 RPC_FUNC(&msg) = (u8)RM_FUNC_PARTITION_ALLOC;
662 RPC_U8(&msg, 0U) = B2U8(secure);
663 RPC_U8(&msg, 1U) = B2U8(isolated);
664 RPC_U8(&msg, 2U) = B2U8(restricted);
665 RPC_U8(&msg, 3U) = B2U8(grant);
666 RPC_U8(&msg, 4U) = B2U8(coherent);
667 RPC_SIZE(&msg) = 3U;
668
669 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
670 if (ret) {
671 printf("%s: secure:%u isolated:%u restricted:%u grant:%u coherent:%u res:%d\n",
672 __func__, secure, isolated, restricted, grant, coherent,
673 RPC_R8(&msg));
674 }
675
676 if (pt)
677 *pt = RPC_U8(&msg, 0U);
678
679 return ret;
680}
681
682int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt)
683{
684 struct udevice *dev = gd->arch.scu_dev;
685 struct sc_rpc_msg_s msg;
686 int size = sizeof(struct sc_rpc_msg_s);
687 int ret;
688
689 RPC_VER(&msg) = SC_RPC_VERSION;
690 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
691 RPC_FUNC(&msg) = (u8)RM_FUNC_PARTITION_FREE;
692 RPC_U8(&msg, 0U) = (u8)pt;
693 RPC_SIZE(&msg) = 2U;
694
695 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
696 if (ret) {
697 printf("%s: pt:%u res:%d\n",
698 __func__, pt, RPC_R8(&msg));
699 }
700
701 return ret;
702}
703
704int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt)
705{
706 struct udevice *dev = gd->arch.scu_dev;
707 struct sc_rpc_msg_s msg;
708 int size = sizeof(struct sc_rpc_msg_s);
709 int ret;
710
711 RPC_VER(&msg) = SC_RPC_VERSION;
712 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
713 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_PARTITION;
714 RPC_SIZE(&msg) = 1U;
715
716 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
717 if (ret)
718 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
719
720 if (pt)
721 *pt = RPC_U8(&msg, 0U);
722
723 return ret;
724}
725
726int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent)
727{
728 struct udevice *dev = gd->arch.scu_dev;
729 struct sc_rpc_msg_s msg;
730 int size = sizeof(struct sc_rpc_msg_s);
731 int ret;
732
733 RPC_VER(&msg) = SC_RPC_VERSION;
734 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
735 RPC_FUNC(&msg) = (u8)RM_FUNC_SET_PARENT;
736 RPC_U8(&msg, 0U) = (u8)pt;
737 RPC_U8(&msg, 1U) = (u8)pt_parent;
738 RPC_SIZE(&msg) = 2U;
739
740 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
741 if (ret) {
742 printf("%s: pt:%u, pt_parent:%u, res:%d\n",
743 __func__, pt, pt_parent, RPC_R8(&msg));
744 }
745
746 return ret;
747}
748
749int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource)
750{
751 struct udevice *dev = gd->arch.scu_dev;
752 struct sc_rpc_msg_s msg;
753 int size = sizeof(struct sc_rpc_msg_s);
754 int ret;
755
756 RPC_VER(&msg) = SC_RPC_VERSION;
757 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
758 RPC_FUNC(&msg) = (u8)RM_FUNC_ASSIGN_RESOURCE;
759 RPC_U16(&msg, 0U) = (u16)resource;
760 RPC_U8(&msg, 2U) = (u8)pt;
761 RPC_SIZE(&msg) = 2U;
762
763 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
764 if (ret) {
765 printf("%s: pt:%u, resource:%u, res:%d\n",
766 __func__, pt, resource, RPC_R8(&msg));
767 }
768
769 return ret;
770}
771
772int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad)
773{
774 struct udevice *dev = gd->arch.scu_dev;
775 struct sc_rpc_msg_s msg;
776 int size = sizeof(struct sc_rpc_msg_s);
777 int ret;
778
779 RPC_VER(&msg) = SC_RPC_VERSION;
780 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
781 RPC_FUNC(&msg) = (u8)RM_FUNC_ASSIGN_PAD;
782 RPC_U16(&msg, 0U) = (u16)pad;
783 RPC_U8(&msg, 2U) = (u8)pt;
784 RPC_SIZE(&msg) = 2U;
785
786 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
787 if (ret) {
788 printf("%s: pt:%u, pad:%u, res:%d\n",
789 __func__, pt, pad, RPC_R8(&msg));
790 }
791
792 return ret;
793}
794
795sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad)
796{
797 struct udevice *dev = gd->arch.scu_dev;
798 struct sc_rpc_msg_s msg;
799 int size = sizeof(struct sc_rpc_msg_s);
800 int ret;
801 u8 result;
802
803 RPC_VER(&msg) = SC_RPC_VERSION;
804 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
805 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_PAD_OWNED;
Ye Li89054fd2022-12-13 05:08:02 +0100806 RPC_U16(&msg, 0U) = (u16)pad;
Peng Fand4191db2019-09-23 10:12:31 +0000807 RPC_SIZE(&msg) = 2U;
808
809 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
810 result = RPC_R8(&msg);
811 if (result != 0 && result != 1) {
812 printf("%s: pad:%d res:%d\n", __func__, pad, RPC_R8(&msg));
813 if (ret) {
814 printf("%s: pad:%d res:%d\n", __func__,
815 pad, RPC_R8(&msg));
816 }
817 }
818
819 return !!result;
820}
821
822int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource,
823 sc_rm_pt_t *pt)
824{
825 struct udevice *dev = gd->arch.scu_dev;
826 struct sc_rpc_msg_s msg;
827 int size = sizeof(struct sc_rpc_msg_s);
828 int ret;
829
830 RPC_VER(&msg) = SC_RPC_VERSION;
831 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
832 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_RESOURCE_OWNER;
833 RPC_U16(&msg, 0U) = (u16)resource;
834 RPC_SIZE(&msg) = 2U;
835
836 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
837 if (pt)
838 *pt = RPC_U8(&msg, 0U);
839
840 return ret;
841}
842
843int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
844 sc_faddr_t address)
845{
846 struct udevice *dev = gd->arch.scu_dev;
847 struct sc_rpc_msg_s msg;
848 int size = sizeof(struct sc_rpc_msg_s);
849 int ret;
850
851 RPC_VER(&msg) = SC_RPC_VERSION;
852 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
853 RPC_FUNC(&msg) = (u8)PM_FUNC_CPU_START;
854 RPC_U32(&msg, 0U) = (u32)(address >> 32ULL);
855 RPC_U32(&msg, 4U) = (u32)address;
856 RPC_U16(&msg, 8U) = (u16)resource;
857 RPC_U8(&msg, 10U) = B2U8(enable);
858 RPC_SIZE(&msg) = 4U;
859
860 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
861 if (ret) {
862 printf("%s: resource:%d address:0x%llx: res:%d\n",
863 __func__, resource, address, RPC_R8(&msg));
864 }
865
866 return ret;
867}
868
Peng Fane89a3912023-06-15 18:09:04 +0800869void sc_pm_reboot(sc_ipc_t ipc, sc_pm_reset_type_t type)
870{
871 struct udevice *dev = gd->arch.scu_dev;
872 struct sc_rpc_msg_s msg;
873 int size = sizeof(struct sc_rpc_msg_s);
874
875 RPC_VER(&msg) = SC_RPC_VERSION;
876 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_PM);
877 RPC_FUNC(&msg) = (u8)(PM_FUNC_REBOOT);
878 RPC_U8(&msg, 0U) = (u8)(type);
879 RPC_SIZE(&msg) = 2U;
880
881 misc_call(dev, SC_TRUE, &msg, size, &msg, size);
882}
883
Igor Opaniuk1dd420e2024-01-31 13:49:25 +0100884int sc_pm_reset_reason(sc_ipc_t ipc, sc_pm_reset_reason_t *reason)
885{
886 struct udevice *dev = gd->arch.scu_dev;
887 struct sc_rpc_msg_s msg;
888 int size = sizeof(struct sc_rpc_msg_s);
889 int ret;
890
891 RPC_VER(&msg) = SC_RPC_VERSION;
892 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
893 RPC_FUNC(&msg) = (u8)PM_FUNC_RESET_REASON;
894 RPC_SIZE(&msg) = 1U;
895
896 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
897 if (ret)
898 printf("%s: res:%d\n", __func__, RPC_U8(&msg, 0U));
899
900 if (reason)
901 *reason = RPC_U8(&msg, 0U);
902
903 return ret;
904}
905
Peng Fand4191db2019-09-23 10:12:31 +0000906int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
907 sc_pm_power_mode_t *mode)
908{
909 struct udevice *dev = gd->arch.scu_dev;
910 struct sc_rpc_msg_s msg;
911 int size = sizeof(struct sc_rpc_msg_s);
912 int ret;
913
914 RPC_VER(&msg) = SC_RPC_VERSION;
915 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
916 RPC_FUNC(&msg) = (u8)PM_FUNC_GET_RESOURCE_POWER_MODE;
917 RPC_U16(&msg, 0U) = (u16)resource;
918 RPC_SIZE(&msg) = 2U;
919
920 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
921 if (ret) {
922 printf("%s: resource:%d: res:%d\n",
923 __func__, resource, RPC_R8(&msg));
924 }
925
926 if (mode)
927 *mode = RPC_U8(&msg, 0U);
928
929 return ret;
930}
931
Peng Fane89a3912023-06-15 18:09:04 +0800932int sc_timer_set_wdog_window(sc_ipc_t ipc, sc_timer_wdog_time_t window)
933{
934 struct udevice *dev = gd->arch.scu_dev;
935 struct sc_rpc_msg_s msg;
936 int size = sizeof(struct sc_rpc_msg_s);
937 int ret;
938
939 RPC_VER(&msg) = SC_RPC_VERSION;
940 RPC_SIZE(&msg) = 2U;
941 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_TIMER);
942 RPC_FUNC(&msg) = (u8)(TIMER_FUNC_SET_WDOG_WINDOW);
943
944 RPC_U32(&msg, 0U) = (u32)(window);
945
946 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
947 if (ret)
948 printf("%s: window:%u: res:%d\n",
949 __func__, window, RPC_R8(&msg));
950
951 return ret;
952}
953
Peng Fand4191db2019-09-23 10:12:31 +0000954int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
955 sc_faddr_t addr)
956{
957 struct udevice *dev = gd->arch.scu_dev;
958 struct sc_rpc_msg_s msg;
959 int size = sizeof(struct sc_rpc_msg_s);
960 int ret;
961
962 RPC_VER(&msg) = SC_RPC_VERSION;
963 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
964 RPC_FUNC(&msg) = (u8)SECO_FUNC_AUTHENTICATE;
965 RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL);
966 RPC_U32(&msg, 4U) = (u32)addr;
967 RPC_U8(&msg, 8U) = (u8)cmd;
968 RPC_SIZE(&msg) = 4U;
969
970 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
971 if (ret)
972 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
973
974 return ret;
975}
976
977int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change)
978{
979 struct udevice *dev = gd->arch.scu_dev;
980 struct sc_rpc_msg_s msg;
981 int size = sizeof(struct sc_rpc_msg_s);
982 int ret;
983
984 RPC_VER(&msg) = SC_RPC_VERSION;
985 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
986 RPC_FUNC(&msg) = (u8)SECO_FUNC_FORWARD_LIFECYCLE;
987 RPC_U32(&msg, 0U) = (u32)change;
988 RPC_SIZE(&msg) = 2U;
989
990 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
991 if (ret) {
992 printf("%s: change:%u, res:%d\n", __func__,
993 change, RPC_R8(&msg));
994 }
995
996 return ret;
997}
998
999int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l,
1000 u32 *uid_h)
1001{
1002 struct udevice *dev = gd->arch.scu_dev;
1003 struct sc_rpc_msg_s msg;
1004 int size = sizeof(struct sc_rpc_msg_s);
1005 int ret;
1006
1007 RPC_VER(&msg) = SC_RPC_VERSION;
1008 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
1009 RPC_FUNC(&msg) = (u8)SECO_FUNC_CHIP_INFO;
1010 RPC_SIZE(&msg) = 1U;
1011
1012 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1013 if (ret)
1014 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
1015
1016 if (uid_l)
1017 *uid_l = RPC_U32(&msg, 0U);
1018
1019 if (uid_h)
1020 *uid_h = RPC_U32(&msg, 4U);
1021
1022 if (lc)
1023 *lc = RPC_U16(&msg, 8U);
1024
1025 if (monotonic)
1026 *monotonic = RPC_U16(&msg, 10U);
1027
1028 return ret;
1029}
1030
1031void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
1032{
1033 struct udevice *dev = gd->arch.scu_dev;
1034 struct sc_rpc_msg_s msg;
1035 int size = sizeof(struct sc_rpc_msg_s);
1036
1037 RPC_VER(&msg) = SC_RPC_VERSION;
1038 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1039 RPC_FUNC(&msg) = (u8)(SECO_FUNC_BUILD_INFO);
1040 RPC_SIZE(&msg) = 1U;
1041
1042 misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1043
1044 if (version)
1045 *version = RPC_U32(&msg, 0U);
1046
1047 if (commit)
1048 *commit = RPC_U32(&msg, 4U);
1049}
1050
Peng Fane89a3912023-06-15 18:09:04 +08001051int sc_seco_v2x_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
1052{
1053 struct udevice *dev = gd->arch.scu_dev;
1054 struct sc_rpc_msg_s msg;
1055 int size = sizeof(struct sc_rpc_msg_s);
1056 int ret;
1057
1058 RPC_VER(&msg) = SC_RPC_VERSION;
1059 RPC_SIZE(&msg) = 1U;
1060 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1061 RPC_FUNC(&msg) = (u8)(SECO_FUNC_V2X_BUILD_INFO);
1062
1063 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1064 if (ret)
1065 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
1066
1067 if (version)
1068 *version = RPC_U32(&msg, 0U);
1069
1070 if (commit)
1071 *commit = RPC_U32(&msg, 4U);
1072
1073 return ret;
1074}
1075
Peng Fand4191db2019-09-23 10:12:31 +00001076int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event)
1077{
1078 struct udevice *dev = gd->arch.scu_dev;
1079 struct sc_rpc_msg_s msg;
1080 int size = sizeof(struct sc_rpc_msg_s);
1081 int ret;
1082
1083 RPC_VER(&msg) = SC_RPC_VERSION;
1084 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
1085 RPC_FUNC(&msg) = (u8)SECO_FUNC_GET_EVENT;
1086 RPC_U8(&msg, 0U) = (u8)idx;
1087 RPC_SIZE(&msg) = 2U;
1088
1089 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1090 if (ret)
1091 printf("%s: idx: %u, res:%d\n", __func__, idx, RPC_R8(&msg));
1092
1093 if (event)
1094 *event = RPC_U32(&msg, 0U);
1095
1096 return ret;
1097}
1098
1099int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
1100 sc_faddr_t export_addr, u16 max_size)
1101{
1102 struct udevice *dev = gd->arch.scu_dev;
1103 struct sc_rpc_msg_s msg;
1104 int size = sizeof(struct sc_rpc_msg_s);
1105 int ret;
1106
1107 RPC_VER(&msg) = SC_RPC_VERSION;
1108 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
1109 RPC_FUNC(&msg) = (u8)SECO_FUNC_GEN_KEY_BLOB;
1110 RPC_U32(&msg, 0U) = (u32)(load_addr >> 32ULL);
1111 RPC_U32(&msg, 4U) = (u32)load_addr;
1112 RPC_U32(&msg, 8U) = (u32)(export_addr >> 32ULL);
1113 RPC_U32(&msg, 12U) = (u32)export_addr;
1114 RPC_U32(&msg, 16U) = (u32)id;
1115 RPC_U16(&msg, 20U) = (u16)max_size;
1116 RPC_SIZE(&msg) = 7U;
1117
1118 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1119 if (ret) {
1120 printf("%s: id: %u, load_addr 0x%llx, export_addr 0x%llx, res:%d\n",
1121 __func__, id, load_addr, export_addr, RPC_R8(&msg));
1122 }
1123
1124 return ret;
1125}
Breno Lima184c7e22019-10-16 18:10:54 -03001126
1127int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr,
1128 u16 dst_size)
1129{
1130 struct udevice *dev = gd->arch.scu_dev;
1131 struct sc_rpc_msg_s msg;
1132 int size = sizeof(struct sc_rpc_msg_s);
1133 int ret;
1134
1135 RPC_VER(&msg) = SC_RPC_VERSION;
1136 RPC_SIZE(&msg) = 4U;
1137 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1138 RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_MP_KEY);
1139
1140 RPC_U32(&msg, 0U) = (u32)(dst_addr >> 32ULL);
1141 RPC_U32(&msg, 4U) = (u32)(dst_addr);
1142 RPC_U16(&msg, 8U) = (u16)(dst_size);
1143
1144 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1145 if (ret)
1146 printf("%s, dst_addr:0x%llx, res:%d\n",
1147 __func__, dst_addr, RPC_R8(&msg));
1148
1149 return ret;
1150}
1151
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +02001152int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size_m,
1153 u8 lock)
Breno Lima184c7e22019-10-16 18:10:54 -03001154{
1155 struct udevice *dev = gd->arch.scu_dev;
1156 struct sc_rpc_msg_s msg;
1157 int size = sizeof(struct sc_rpc_msg_s);
1158 int ret;
1159
1160 RPC_VER(&msg) = SC_RPC_VERSION;
1161 RPC_SIZE(&msg) = 4U;
1162 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1163 RPC_FUNC(&msg) = (u8)(SECO_FUNC_UPDATE_MPMR);
1164
1165 RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL);
1166 RPC_U32(&msg, 4U) = (u32)(addr);
1167 RPC_U8(&msg, 8U) = (u8)(size_m);
1168 RPC_U8(&msg, 9U) = (u8)(lock);
1169
1170 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1171 if (ret)
1172 printf("%s, addr:0x%llx, size_m:%x, lock:0x%x, res:%d\n",
1173 __func__, addr, size_m, lock, RPC_R8(&msg));
1174 return ret;
1175}
1176
1177int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr,
1178 u16 msg_size, sc_faddr_t dst_addr,
1179 u16 dst_size)
1180{
1181 struct udevice *dev = gd->arch.scu_dev;
1182 struct sc_rpc_msg_s msg;
1183 int size = sizeof(struct sc_rpc_msg_s);
1184 int ret;
1185
1186 RPC_VER(&msg) = SC_RPC_VERSION;
1187 RPC_SIZE(&msg) = 6U;
1188 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1189 RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_MP_SIGN);
1190
1191 RPC_U32(&msg, 0U) = (u32)(msg_addr >> 32ULL);
1192 RPC_U32(&msg, 4U) = (u32)(msg_addr);
1193 RPC_U32(&msg, 8U) = (u32)(dst_addr >> 32ULL);
1194 RPC_U32(&msg, 12U) = (u32)(dst_addr);
1195 RPC_U16(&msg, 16U) = (u16)(msg_size);
1196 RPC_U16(&msg, 18U) = (u16)(dst_size);
1197
1198 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1199 if (ret)
1200 printf("%s, msg_addr:0x%llx, msg_size:%x, dst_addr:0x%llx,"
1201 "dst_size:%x, res:%d\n", __func__, msg_addr, msg_size,
1202 dst_addr, dst_size, RPC_R8(&msg));
1203
1204 return ret;
1205}
Ye Li24b5dae2019-11-13 21:20:43 -08001206
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +02001207int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access,
1208 u32 *data0, u32 *data1, u32 *data2, u32 *data3,
1209 u32 *data4, u8 size)
1210{
1211 struct udevice *dev = gd->arch.scu_dev;
1212 struct sc_rpc_msg_s msg;
1213 int msg_size = sizeof(struct sc_rpc_msg_s);
1214 int ret;
1215
1216 RPC_VER(&msg) = SC_RPC_VERSION;
1217 RPC_SIZE(&msg) = 7U;
1218 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1219 RPC_FUNC(&msg) = (u8)(SECO_FUNC_SECVIO_CONFIG);
1220
1221 RPC_U32(&msg, 0U) = (u32)(*data0);
1222 RPC_U32(&msg, 4U) = (u32)(*data1);
1223 RPC_U32(&msg, 8U) = (u32)(*data2);
1224 RPC_U32(&msg, 12U) = (u32)(*data3);
1225 RPC_U32(&msg, 16U) = (u32)(*data4);
1226 RPC_U8(&msg, 20U) = (u8)(id);
1227 RPC_U8(&msg, 21U) = (u8)(access);
1228 RPC_U8(&msg, 22U) = (u8)(size);
1229
1230 ret = misc_call(dev, SC_FALSE, &msg, msg_size, &msg, msg_size);
1231 if (ret)
1232 printf("%s, id:0x%x, access:%x, res:%d\n",
1233 __func__, id, access, RPC_R8(&msg));
1234
1235 *data0 = (u32)RPC_U32(&msg, 0U);
1236 *data1 = (u32)RPC_U32(&msg, 4U);
1237 *data2 = (u32)RPC_U32(&msg, 8U);
1238 *data3 = (u32)RPC_U32(&msg, 12U);
1239 *data4 = (u32)RPC_U32(&msg, 16U);
1240
1241 return ret;
1242}
1243
1244int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data)
Ye Li24b5dae2019-11-13 21:20:43 -08001245{
1246 struct udevice *dev = gd->arch.scu_dev;
1247 struct sc_rpc_msg_s msg;
1248 int size = sizeof(struct sc_rpc_msg_s);
1249 int ret;
1250
1251 RPC_VER(&msg) = SC_RPC_VERSION;
1252 RPC_SIZE(&msg) = 3U;
1253 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1254 RPC_FUNC(&msg) = (u8)(SECO_FUNC_SECVIO_DGO_CONFIG);
1255
1256 RPC_U32(&msg, 0U) = (u32)(*data);
1257 RPC_U8(&msg, 4U) = (u8)(id);
1258 RPC_U8(&msg, 5U) = (u8)(access);
1259
1260 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1261 if (ret)
1262 printf("%s, id:0x%x, access:%x, res:%d\n",
1263 __func__, id, access, RPC_R8(&msg));
1264
1265 if (data)
1266 *data = RPC_U32(&msg, 0U);
1267
1268 return ret;
1269}