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