blob: 27ecce710fcbb4f3d93b57641bae39c9216b066a [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
8#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>
14#include <asm/arch/sci/sci.h>
15#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 Fan55486382018-10-18 14:28:12 +0200484/* RM */
485sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr)
486{
487 struct udevice *dev = gd->arch.scu_dev;
488 int size = sizeof(struct sc_rpc_msg_s);
489 struct sc_rpc_msg_s msg;
490 int ret;
491 sc_err_t result;
492
493 if (!dev)
494 hang();
495
496 RPC_VER(&msg) = SC_RPC_VERSION;
497 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
498 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_MEMREG_OWNED;
499 RPC_U8(&msg, 0U) = (u8)mr;
500 RPC_SIZE(&msg) = 2U;
501
502 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
503 result = RPC_R8(&msg);
504
505 if (result != 0 && result != 1) {
506 printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
507 if (ret)
508 printf("%s: mr:%d res:%d\n", __func__, mr,
509 RPC_R8(&msg));
510 }
511
512 return (sc_bool_t)result;
513}
514
Peng Fand4191db2019-09-23 10:12:31 +0000515int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
516 sc_faddr_t addr_end)
Peng Fanb612a302019-08-26 08:12:03 +0000517{
518 struct udevice *dev = gd->arch.scu_dev;
Peng Fand4191db2019-09-23 10:12:31 +0000519 int size = sizeof(struct sc_rpc_msg_s);
Peng Fanb612a302019-08-26 08:12:03 +0000520 struct sc_rpc_msg_s msg;
Peng Fand4191db2019-09-23 10:12:31 +0000521 int ret;
522
523 if (!dev)
524 hang();
525
526 RPC_VER(&msg) = SC_RPC_VERSION;
527 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM);
528 RPC_FUNC(&msg) = (u8)(RM_FUNC_FIND_MEMREG);
529 RPC_U32(&msg, 0U) = (u32)(addr_start >> 32ULL);
530 RPC_U32(&msg, 4U) = (u32)(addr_start);
531 RPC_U32(&msg, 8U) = (u32)(addr_end >> 32ULL);
532 RPC_U32(&msg, 12U) = (u32)(addr_end);
533 RPC_SIZE(&msg) = 5U;
534
535 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
536 if (ret)
537 printf("%s: start:0x%llx, end:0x%llx res:%d\n", __func__, addr_start, addr_end, RPC_R8(&msg));
538
539 if (mr)
540 *mr = RPC_U8(&msg, 0U);
541
542 return ret;
543}
544
545int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr,
546 sc_rm_pt_t pt, sc_rm_perm_t perm)
547{
548 struct udevice *dev = gd->arch.scu_dev;
Peng Fanb612a302019-08-26 08:12:03 +0000549 int size = sizeof(struct sc_rpc_msg_s);
Peng Fand4191db2019-09-23 10:12:31 +0000550 struct sc_rpc_msg_s msg;
Peng Fanb612a302019-08-26 08:12:03 +0000551 int ret;
552
Peng Fand4191db2019-09-23 10:12:31 +0000553 if (!dev)
554 hang();
555
Peng Fanb612a302019-08-26 08:12:03 +0000556 RPC_VER(&msg) = SC_RPC_VERSION;
Peng Fand4191db2019-09-23 10:12:31 +0000557 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM);
558 RPC_FUNC(&msg) = (u8)(RM_FUNC_SET_MEMREG_PERMISSIONS);
559 RPC_U8(&msg, 0U) = (u8)(mr);
560 RPC_U8(&msg, 1U) = (u8)(pt);
561 RPC_U8(&msg, 2U) = (u8)(perm);
Peng Fanb612a302019-08-26 08:12:03 +0000562 RPC_SIZE(&msg) = 2U;
563
564 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
Peng Fand4191db2019-09-23 10:12:31 +0000565 if (ret) {
566 printf("%s: mr:%u, pt:%u, perm:%u, res:%d\n", __func__,
567 mr, pt, perm, RPC_R8(&msg));
568 }
Peng Fanb612a302019-08-26 08:12:03 +0000569
570 return ret;
571}
572
Peng Fan55486382018-10-18 14:28:12 +0200573int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
574 sc_faddr_t *addr_end)
575{
576 struct udevice *dev = gd->arch.scu_dev;
577 int size = sizeof(struct sc_rpc_msg_s);
578 struct sc_rpc_msg_s msg;
579 int ret;
580
581 if (!dev)
582 hang();
583
584 RPC_VER(&msg) = SC_RPC_VERSION;
585 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
586 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_MEMREG_INFO;
587 RPC_U8(&msg, 0U) = (u8)mr;
588 RPC_SIZE(&msg) = 2U;
589
590 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
591 if (ret)
592 printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
593
594 if (addr_start)
595 *addr_start = ((u64)RPC_U32(&msg, 0U) << 32U) |
596 RPC_U32(&msg, 4U);
597
598 if (addr_end)
599 *addr_end = ((u64)RPC_U32(&msg, 8U) << 32U) |
600 RPC_U32(&msg, 12U);
601
602 return ret;
603}
604
605sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource)
606{
607 struct udevice *dev = gd->arch.scu_dev;
608 int size = sizeof(struct sc_rpc_msg_s);
609 struct sc_rpc_msg_s msg;
610 int ret;
611 u8 result;
612
613 if (!dev)
614 hang();
615
616 RPC_VER(&msg) = SC_RPC_VERSION;
617 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
618 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_RESOURCE_OWNED;
619 RPC_U16(&msg, 0U) = (u16)resource;
620 RPC_SIZE(&msg) = 2U;
621
622 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
623 result = RPC_R8(&msg);
624 if (result != 0 && result != 1) {
625 printf("%s: resource:%d res:%d\n",
626 __func__, resource, RPC_R8(&msg));
627 if (ret)
628 printf("%s: res:%d res:%d\n", __func__, resource,
629 RPC_R8(&msg));
630 }
631
632 return !!result;
633}
Peng Fand4191db2019-09-23 10:12:31 +0000634
635int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
636 sc_bool_t isolated, sc_bool_t restricted,
637 sc_bool_t grant, sc_bool_t coherent)
638{
639 struct udevice *dev = gd->arch.scu_dev;
640 struct sc_rpc_msg_s msg;
641 int size = sizeof(struct sc_rpc_msg_s);
642 int ret;
643
644 RPC_VER(&msg) = SC_RPC_VERSION;
645 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
646 RPC_FUNC(&msg) = (u8)RM_FUNC_PARTITION_ALLOC;
647 RPC_U8(&msg, 0U) = B2U8(secure);
648 RPC_U8(&msg, 1U) = B2U8(isolated);
649 RPC_U8(&msg, 2U) = B2U8(restricted);
650 RPC_U8(&msg, 3U) = B2U8(grant);
651 RPC_U8(&msg, 4U) = B2U8(coherent);
652 RPC_SIZE(&msg) = 3U;
653
654 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
655 if (ret) {
656 printf("%s: secure:%u isolated:%u restricted:%u grant:%u coherent:%u res:%d\n",
657 __func__, secure, isolated, restricted, grant, coherent,
658 RPC_R8(&msg));
659 }
660
661 if (pt)
662 *pt = RPC_U8(&msg, 0U);
663
664 return ret;
665}
666
667int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt)
668{
669 struct udevice *dev = gd->arch.scu_dev;
670 struct sc_rpc_msg_s msg;
671 int size = sizeof(struct sc_rpc_msg_s);
672 int ret;
673
674 RPC_VER(&msg) = SC_RPC_VERSION;
675 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
676 RPC_FUNC(&msg) = (u8)RM_FUNC_PARTITION_FREE;
677 RPC_U8(&msg, 0U) = (u8)pt;
678 RPC_SIZE(&msg) = 2U;
679
680 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
681 if (ret) {
682 printf("%s: pt:%u res:%d\n",
683 __func__, pt, RPC_R8(&msg));
684 }
685
686 return ret;
687}
688
689int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt)
690{
691 struct udevice *dev = gd->arch.scu_dev;
692 struct sc_rpc_msg_s msg;
693 int size = sizeof(struct sc_rpc_msg_s);
694 int ret;
695
696 RPC_VER(&msg) = SC_RPC_VERSION;
697 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
698 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_PARTITION;
699 RPC_SIZE(&msg) = 1U;
700
701 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
702 if (ret)
703 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
704
705 if (pt)
706 *pt = RPC_U8(&msg, 0U);
707
708 return ret;
709}
710
711int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent)
712{
713 struct udevice *dev = gd->arch.scu_dev;
714 struct sc_rpc_msg_s msg;
715 int size = sizeof(struct sc_rpc_msg_s);
716 int ret;
717
718 RPC_VER(&msg) = SC_RPC_VERSION;
719 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
720 RPC_FUNC(&msg) = (u8)RM_FUNC_SET_PARENT;
721 RPC_U8(&msg, 0U) = (u8)pt;
722 RPC_U8(&msg, 1U) = (u8)pt_parent;
723 RPC_SIZE(&msg) = 2U;
724
725 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
726 if (ret) {
727 printf("%s: pt:%u, pt_parent:%u, res:%d\n",
728 __func__, pt, pt_parent, RPC_R8(&msg));
729 }
730
731 return ret;
732}
733
734int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource)
735{
736 struct udevice *dev = gd->arch.scu_dev;
737 struct sc_rpc_msg_s msg;
738 int size = sizeof(struct sc_rpc_msg_s);
739 int ret;
740
741 RPC_VER(&msg) = SC_RPC_VERSION;
742 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
743 RPC_FUNC(&msg) = (u8)RM_FUNC_ASSIGN_RESOURCE;
744 RPC_U16(&msg, 0U) = (u16)resource;
745 RPC_U8(&msg, 2U) = (u8)pt;
746 RPC_SIZE(&msg) = 2U;
747
748 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
749 if (ret) {
750 printf("%s: pt:%u, resource:%u, res:%d\n",
751 __func__, pt, resource, RPC_R8(&msg));
752 }
753
754 return ret;
755}
756
757int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad)
758{
759 struct udevice *dev = gd->arch.scu_dev;
760 struct sc_rpc_msg_s msg;
761 int size = sizeof(struct sc_rpc_msg_s);
762 int ret;
763
764 RPC_VER(&msg) = SC_RPC_VERSION;
765 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
766 RPC_FUNC(&msg) = (u8)RM_FUNC_ASSIGN_PAD;
767 RPC_U16(&msg, 0U) = (u16)pad;
768 RPC_U8(&msg, 2U) = (u8)pt;
769 RPC_SIZE(&msg) = 2U;
770
771 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
772 if (ret) {
773 printf("%s: pt:%u, pad:%u, res:%d\n",
774 __func__, pt, pad, RPC_R8(&msg));
775 }
776
777 return ret;
778}
779
780sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad)
781{
782 struct udevice *dev = gd->arch.scu_dev;
783 struct sc_rpc_msg_s msg;
784 int size = sizeof(struct sc_rpc_msg_s);
785 int ret;
786 u8 result;
787
788 RPC_VER(&msg) = SC_RPC_VERSION;
789 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
790 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_PAD_OWNED;
791 RPC_U8(&msg, 0U) = (u8)pad;
792 RPC_SIZE(&msg) = 2U;
793
794 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
795 result = RPC_R8(&msg);
796 if (result != 0 && result != 1) {
797 printf("%s: pad:%d res:%d\n", __func__, pad, RPC_R8(&msg));
798 if (ret) {
799 printf("%s: pad:%d res:%d\n", __func__,
800 pad, RPC_R8(&msg));
801 }
802 }
803
804 return !!result;
805}
806
807int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource,
808 sc_rm_pt_t *pt)
809{
810 struct udevice *dev = gd->arch.scu_dev;
811 struct sc_rpc_msg_s msg;
812 int size = sizeof(struct sc_rpc_msg_s);
813 int ret;
814
815 RPC_VER(&msg) = SC_RPC_VERSION;
816 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
817 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_RESOURCE_OWNER;
818 RPC_U16(&msg, 0U) = (u16)resource;
819 RPC_SIZE(&msg) = 2U;
820
821 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
822 if (pt)
823 *pt = RPC_U8(&msg, 0U);
824
825 return ret;
826}
827
828int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
829 sc_faddr_t address)
830{
831 struct udevice *dev = gd->arch.scu_dev;
832 struct sc_rpc_msg_s msg;
833 int size = sizeof(struct sc_rpc_msg_s);
834 int ret;
835
836 RPC_VER(&msg) = SC_RPC_VERSION;
837 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
838 RPC_FUNC(&msg) = (u8)PM_FUNC_CPU_START;
839 RPC_U32(&msg, 0U) = (u32)(address >> 32ULL);
840 RPC_U32(&msg, 4U) = (u32)address;
841 RPC_U16(&msg, 8U) = (u16)resource;
842 RPC_U8(&msg, 10U) = B2U8(enable);
843 RPC_SIZE(&msg) = 4U;
844
845 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
846 if (ret) {
847 printf("%s: resource:%d address:0x%llx: res:%d\n",
848 __func__, resource, address, RPC_R8(&msg));
849 }
850
851 return ret;
852}
853
854int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
855 sc_pm_power_mode_t *mode)
856{
857 struct udevice *dev = gd->arch.scu_dev;
858 struct sc_rpc_msg_s msg;
859 int size = sizeof(struct sc_rpc_msg_s);
860 int ret;
861
862 RPC_VER(&msg) = SC_RPC_VERSION;
863 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
864 RPC_FUNC(&msg) = (u8)PM_FUNC_GET_RESOURCE_POWER_MODE;
865 RPC_U16(&msg, 0U) = (u16)resource;
866 RPC_SIZE(&msg) = 2U;
867
868 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
869 if (ret) {
870 printf("%s: resource:%d: res:%d\n",
871 __func__, resource, RPC_R8(&msg));
872 }
873
874 if (mode)
875 *mode = RPC_U8(&msg, 0U);
876
877 return ret;
878}
879
880int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
881 sc_faddr_t addr)
882{
883 struct udevice *dev = gd->arch.scu_dev;
884 struct sc_rpc_msg_s msg;
885 int size = sizeof(struct sc_rpc_msg_s);
886 int ret;
887
888 RPC_VER(&msg) = SC_RPC_VERSION;
889 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
890 RPC_FUNC(&msg) = (u8)SECO_FUNC_AUTHENTICATE;
891 RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL);
892 RPC_U32(&msg, 4U) = (u32)addr;
893 RPC_U8(&msg, 8U) = (u8)cmd;
894 RPC_SIZE(&msg) = 4U;
895
896 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
897 if (ret)
898 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
899
900 return ret;
901}
902
903int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change)
904{
905 struct udevice *dev = gd->arch.scu_dev;
906 struct sc_rpc_msg_s msg;
907 int size = sizeof(struct sc_rpc_msg_s);
908 int ret;
909
910 RPC_VER(&msg) = SC_RPC_VERSION;
911 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
912 RPC_FUNC(&msg) = (u8)SECO_FUNC_FORWARD_LIFECYCLE;
913 RPC_U32(&msg, 0U) = (u32)change;
914 RPC_SIZE(&msg) = 2U;
915
916 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
917 if (ret) {
918 printf("%s: change:%u, res:%d\n", __func__,
919 change, RPC_R8(&msg));
920 }
921
922 return ret;
923}
924
925int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l,
926 u32 *uid_h)
927{
928 struct udevice *dev = gd->arch.scu_dev;
929 struct sc_rpc_msg_s msg;
930 int size = sizeof(struct sc_rpc_msg_s);
931 int ret;
932
933 RPC_VER(&msg) = SC_RPC_VERSION;
934 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
935 RPC_FUNC(&msg) = (u8)SECO_FUNC_CHIP_INFO;
936 RPC_SIZE(&msg) = 1U;
937
938 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
939 if (ret)
940 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
941
942 if (uid_l)
943 *uid_l = RPC_U32(&msg, 0U);
944
945 if (uid_h)
946 *uid_h = RPC_U32(&msg, 4U);
947
948 if (lc)
949 *lc = RPC_U16(&msg, 8U);
950
951 if (monotonic)
952 *monotonic = RPC_U16(&msg, 10U);
953
954 return ret;
955}
956
957void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
958{
959 struct udevice *dev = gd->arch.scu_dev;
960 struct sc_rpc_msg_s msg;
961 int size = sizeof(struct sc_rpc_msg_s);
962
963 RPC_VER(&msg) = SC_RPC_VERSION;
964 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
965 RPC_FUNC(&msg) = (u8)(SECO_FUNC_BUILD_INFO);
966 RPC_SIZE(&msg) = 1U;
967
968 misc_call(dev, SC_FALSE, &msg, size, &msg, size);
969
970 if (version)
971 *version = RPC_U32(&msg, 0U);
972
973 if (commit)
974 *commit = RPC_U32(&msg, 4U);
975}
976
977int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event)
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_GET_EVENT;
987 RPC_U8(&msg, 0U) = (u8)idx;
988 RPC_SIZE(&msg) = 2U;
989
990 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
991 if (ret)
992 printf("%s: idx: %u, res:%d\n", __func__, idx, RPC_R8(&msg));
993
994 if (event)
995 *event = RPC_U32(&msg, 0U);
996
997 return ret;
998}
999
1000int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
1001 sc_faddr_t export_addr, u16 max_size)
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_GEN_KEY_BLOB;
1011 RPC_U32(&msg, 0U) = (u32)(load_addr >> 32ULL);
1012 RPC_U32(&msg, 4U) = (u32)load_addr;
1013 RPC_U32(&msg, 8U) = (u32)(export_addr >> 32ULL);
1014 RPC_U32(&msg, 12U) = (u32)export_addr;
1015 RPC_U32(&msg, 16U) = (u32)id;
1016 RPC_U16(&msg, 20U) = (u16)max_size;
1017 RPC_SIZE(&msg) = 7U;
1018
1019 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1020 if (ret) {
1021 printf("%s: id: %u, load_addr 0x%llx, export_addr 0x%llx, res:%d\n",
1022 __func__, id, load_addr, export_addr, RPC_R8(&msg));
1023 }
1024
1025 return ret;
1026}
Breno Lima184c7e22019-10-16 18:10:54 -03001027
1028int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr,
1029 u16 dst_size)
1030{
1031 struct udevice *dev = gd->arch.scu_dev;
1032 struct sc_rpc_msg_s msg;
1033 int size = sizeof(struct sc_rpc_msg_s);
1034 int ret;
1035
1036 RPC_VER(&msg) = SC_RPC_VERSION;
1037 RPC_SIZE(&msg) = 4U;
1038 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1039 RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_MP_KEY);
1040
1041 RPC_U32(&msg, 0U) = (u32)(dst_addr >> 32ULL);
1042 RPC_U32(&msg, 4U) = (u32)(dst_addr);
1043 RPC_U16(&msg, 8U) = (u16)(dst_size);
1044
1045 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1046 if (ret)
1047 printf("%s, dst_addr:0x%llx, res:%d\n",
1048 __func__, dst_addr, RPC_R8(&msg));
1049
1050 return ret;
1051}
1052
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +02001053int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size_m,
1054 u8 lock)
Breno Lima184c7e22019-10-16 18:10:54 -03001055{
1056 struct udevice *dev = gd->arch.scu_dev;
1057 struct sc_rpc_msg_s msg;
1058 int size = sizeof(struct sc_rpc_msg_s);
1059 int ret;
1060
1061 RPC_VER(&msg) = SC_RPC_VERSION;
1062 RPC_SIZE(&msg) = 4U;
1063 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1064 RPC_FUNC(&msg) = (u8)(SECO_FUNC_UPDATE_MPMR);
1065
1066 RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL);
1067 RPC_U32(&msg, 4U) = (u32)(addr);
1068 RPC_U8(&msg, 8U) = (u8)(size_m);
1069 RPC_U8(&msg, 9U) = (u8)(lock);
1070
1071 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1072 if (ret)
1073 printf("%s, addr:0x%llx, size_m:%x, lock:0x%x, res:%d\n",
1074 __func__, addr, size_m, lock, RPC_R8(&msg));
1075 return ret;
1076}
1077
1078int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr,
1079 u16 msg_size, sc_faddr_t dst_addr,
1080 u16 dst_size)
1081{
1082 struct udevice *dev = gd->arch.scu_dev;
1083 struct sc_rpc_msg_s msg;
1084 int size = sizeof(struct sc_rpc_msg_s);
1085 int ret;
1086
1087 RPC_VER(&msg) = SC_RPC_VERSION;
1088 RPC_SIZE(&msg) = 6U;
1089 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1090 RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_MP_SIGN);
1091
1092 RPC_U32(&msg, 0U) = (u32)(msg_addr >> 32ULL);
1093 RPC_U32(&msg, 4U) = (u32)(msg_addr);
1094 RPC_U32(&msg, 8U) = (u32)(dst_addr >> 32ULL);
1095 RPC_U32(&msg, 12U) = (u32)(dst_addr);
1096 RPC_U16(&msg, 16U) = (u16)(msg_size);
1097 RPC_U16(&msg, 18U) = (u16)(dst_size);
1098
1099 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1100 if (ret)
1101 printf("%s, msg_addr:0x%llx, msg_size:%x, dst_addr:0x%llx,"
1102 "dst_size:%x, res:%d\n", __func__, msg_addr, msg_size,
1103 dst_addr, dst_size, RPC_R8(&msg));
1104
1105 return ret;
1106}
Ye Li24b5dae2019-11-13 21:20:43 -08001107
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +02001108int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access,
1109 u32 *data0, u32 *data1, u32 *data2, u32 *data3,
1110 u32 *data4, u8 size)
1111{
1112 struct udevice *dev = gd->arch.scu_dev;
1113 struct sc_rpc_msg_s msg;
1114 int msg_size = sizeof(struct sc_rpc_msg_s);
1115 int ret;
1116
1117 RPC_VER(&msg) = SC_RPC_VERSION;
1118 RPC_SIZE(&msg) = 7U;
1119 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1120 RPC_FUNC(&msg) = (u8)(SECO_FUNC_SECVIO_CONFIG);
1121
1122 RPC_U32(&msg, 0U) = (u32)(*data0);
1123 RPC_U32(&msg, 4U) = (u32)(*data1);
1124 RPC_U32(&msg, 8U) = (u32)(*data2);
1125 RPC_U32(&msg, 12U) = (u32)(*data3);
1126 RPC_U32(&msg, 16U) = (u32)(*data4);
1127 RPC_U8(&msg, 20U) = (u8)(id);
1128 RPC_U8(&msg, 21U) = (u8)(access);
1129 RPC_U8(&msg, 22U) = (u8)(size);
1130
1131 ret = misc_call(dev, SC_FALSE, &msg, msg_size, &msg, msg_size);
1132 if (ret)
1133 printf("%s, id:0x%x, access:%x, res:%d\n",
1134 __func__, id, access, RPC_R8(&msg));
1135
1136 *data0 = (u32)RPC_U32(&msg, 0U);
1137 *data1 = (u32)RPC_U32(&msg, 4U);
1138 *data2 = (u32)RPC_U32(&msg, 8U);
1139 *data3 = (u32)RPC_U32(&msg, 12U);
1140 *data4 = (u32)RPC_U32(&msg, 16U);
1141
1142 return ret;
1143}
1144
1145int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data)
Ye Li24b5dae2019-11-13 21:20:43 -08001146{
1147 struct udevice *dev = gd->arch.scu_dev;
1148 struct sc_rpc_msg_s msg;
1149 int size = sizeof(struct sc_rpc_msg_s);
1150 int ret;
1151
1152 RPC_VER(&msg) = SC_RPC_VERSION;
1153 RPC_SIZE(&msg) = 3U;
1154 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1155 RPC_FUNC(&msg) = (u8)(SECO_FUNC_SECVIO_DGO_CONFIG);
1156
1157 RPC_U32(&msg, 0U) = (u32)(*data);
1158 RPC_U8(&msg, 4U) = (u8)(id);
1159 RPC_U8(&msg, 5U) = (u8)(access);
1160
1161 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1162 if (ret)
1163 printf("%s, id:0x%x, access:%x, res:%d\n",
1164 __func__, id, access, RPC_R8(&msg));
1165
1166 if (data)
1167 *data = RPC_U32(&msg, 0U);
1168
1169 return ret;
1170}