blob: 3e38edbf5dc3499a6db2c1928304e0af9259f94d [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>
Peng Fan55486382018-10-18 14:28:12 +020011#include <asm/io.h>
12#include <dm.h>
13#include <asm/arch/sci/sci.h>
14#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
377void sc_misc_build_info(sc_ipc_t ipc, u32 *build, u32 *commit)
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_SVC(&msg) = SC_RPC_SVC_MISC;
389 RPC_FUNC(&msg) = MISC_FUNC_BUILD_INFO;
390 RPC_SIZE(&msg) = 1;
391
392 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
393 if (ret < 0) {
394 printf("%s: err: %d\n", __func__, ret);
395 return;
396 }
397
398 if (build)
399 *build = RPC_U32(&msg, 0);
400 if (commit)
401 *commit = RPC_U32(&msg, 4);
402}
403
404int sc_misc_otp_fuse_read(sc_ipc_t ipc, u32 word, u32 *val)
405{
406 struct udevice *dev = gd->arch.scu_dev;
407 int size = sizeof(struct sc_rpc_msg_s);
408 struct sc_rpc_msg_s msg;
409 int ret;
410
411 if (!dev)
412 hang();
413
414 RPC_VER(&msg) = SC_RPC_VERSION;
415 RPC_SVC(&msg) = SC_RPC_SVC_MISC;
416 RPC_FUNC(&msg) = MISC_FUNC_OTP_FUSE_READ;
417 RPC_U32(&msg, 0) = word;
418 RPC_SIZE(&msg) = 2;
419
420 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
421 if (ret < 0)
422 return ret;
423
424 if (val)
425 *val = RPC_U32(&msg, 0U);
426
427 return 0;
428}
429
Peng Fanba44e012019-05-05 13:23:51 +0000430int sc_misc_get_temp(sc_ipc_t ipc, sc_rsrc_t resource, sc_misc_temp_t temp,
431 s16 *celsius, s8 *tenths)
432{
433 struct udevice *dev = gd->arch.scu_dev;
434 int size = sizeof(struct sc_rpc_msg_s);
435 struct sc_rpc_msg_s msg;
436 int ret;
437
438 RPC_VER(&msg) = SC_RPC_VERSION;
439 RPC_SVC(&msg) = (u8)SC_RPC_SVC_MISC;
440 RPC_FUNC(&msg) = (u8)MISC_FUNC_GET_TEMP;
441 RPC_U16(&msg, 0U) = (u16)resource;
442 RPC_U8(&msg, 2U) = (u8)temp;
443 RPC_SIZE(&msg) = 2U;
444
445 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
446 if (ret < 0)
447 return ret;
448
449 if (celsius)
450 *celsius = RPC_I16(&msg, 0U);
451
452 if (tenths)
453 *tenths = RPC_I8(&msg, 2U);
454
455 return 0;
456}
457
Peng Fan55486382018-10-18 14:28:12 +0200458/* RM */
459sc_bool_t sc_rm_is_memreg_owned(sc_ipc_t ipc, sc_rm_mr_t mr)
460{
461 struct udevice *dev = gd->arch.scu_dev;
462 int size = sizeof(struct sc_rpc_msg_s);
463 struct sc_rpc_msg_s msg;
464 int ret;
465 sc_err_t result;
466
467 if (!dev)
468 hang();
469
470 RPC_VER(&msg) = SC_RPC_VERSION;
471 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
472 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_MEMREG_OWNED;
473 RPC_U8(&msg, 0U) = (u8)mr;
474 RPC_SIZE(&msg) = 2U;
475
476 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
477 result = RPC_R8(&msg);
478
479 if (result != 0 && result != 1) {
480 printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
481 if (ret)
482 printf("%s: mr:%d res:%d\n", __func__, mr,
483 RPC_R8(&msg));
484 }
485
486 return (sc_bool_t)result;
487}
488
Peng Fand4191db2019-09-23 10:12:31 +0000489int sc_rm_find_memreg(sc_ipc_t ipc, sc_rm_mr_t *mr, sc_faddr_t addr_start,
490 sc_faddr_t addr_end)
Peng Fanb612a302019-08-26 08:12:03 +0000491{
492 struct udevice *dev = gd->arch.scu_dev;
Peng Fand4191db2019-09-23 10:12:31 +0000493 int size = sizeof(struct sc_rpc_msg_s);
Peng Fanb612a302019-08-26 08:12:03 +0000494 struct sc_rpc_msg_s msg;
Peng Fand4191db2019-09-23 10:12:31 +0000495 int ret;
496
497 if (!dev)
498 hang();
499
500 RPC_VER(&msg) = SC_RPC_VERSION;
501 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM);
502 RPC_FUNC(&msg) = (u8)(RM_FUNC_FIND_MEMREG);
503 RPC_U32(&msg, 0U) = (u32)(addr_start >> 32ULL);
504 RPC_U32(&msg, 4U) = (u32)(addr_start);
505 RPC_U32(&msg, 8U) = (u32)(addr_end >> 32ULL);
506 RPC_U32(&msg, 12U) = (u32)(addr_end);
507 RPC_SIZE(&msg) = 5U;
508
509 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
510 if (ret)
511 printf("%s: start:0x%llx, end:0x%llx res:%d\n", __func__, addr_start, addr_end, RPC_R8(&msg));
512
513 if (mr)
514 *mr = RPC_U8(&msg, 0U);
515
516 return ret;
517}
518
519int sc_rm_set_memreg_permissions(sc_ipc_t ipc, sc_rm_mr_t mr,
520 sc_rm_pt_t pt, sc_rm_perm_t perm)
521{
522 struct udevice *dev = gd->arch.scu_dev;
Peng Fanb612a302019-08-26 08:12:03 +0000523 int size = sizeof(struct sc_rpc_msg_s);
Peng Fand4191db2019-09-23 10:12:31 +0000524 struct sc_rpc_msg_s msg;
Peng Fanb612a302019-08-26 08:12:03 +0000525 int ret;
526
Peng Fand4191db2019-09-23 10:12:31 +0000527 if (!dev)
528 hang();
529
Peng Fanb612a302019-08-26 08:12:03 +0000530 RPC_VER(&msg) = SC_RPC_VERSION;
Peng Fand4191db2019-09-23 10:12:31 +0000531 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_RM);
532 RPC_FUNC(&msg) = (u8)(RM_FUNC_SET_MEMREG_PERMISSIONS);
533 RPC_U8(&msg, 0U) = (u8)(mr);
534 RPC_U8(&msg, 1U) = (u8)(pt);
535 RPC_U8(&msg, 2U) = (u8)(perm);
Peng Fanb612a302019-08-26 08:12:03 +0000536 RPC_SIZE(&msg) = 2U;
537
538 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
Peng Fand4191db2019-09-23 10:12:31 +0000539 if (ret) {
540 printf("%s: mr:%u, pt:%u, perm:%u, res:%d\n", __func__,
541 mr, pt, perm, RPC_R8(&msg));
542 }
Peng Fanb612a302019-08-26 08:12:03 +0000543
544 return ret;
545}
546
Peng Fan55486382018-10-18 14:28:12 +0200547int sc_rm_get_memreg_info(sc_ipc_t ipc, sc_rm_mr_t mr, sc_faddr_t *addr_start,
548 sc_faddr_t *addr_end)
549{
550 struct udevice *dev = gd->arch.scu_dev;
551 int size = sizeof(struct sc_rpc_msg_s);
552 struct sc_rpc_msg_s msg;
553 int ret;
554
555 if (!dev)
556 hang();
557
558 RPC_VER(&msg) = SC_RPC_VERSION;
559 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
560 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_MEMREG_INFO;
561 RPC_U8(&msg, 0U) = (u8)mr;
562 RPC_SIZE(&msg) = 2U;
563
564 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
565 if (ret)
566 printf("%s: mr:%d res:%d\n", __func__, mr, RPC_R8(&msg));
567
568 if (addr_start)
569 *addr_start = ((u64)RPC_U32(&msg, 0U) << 32U) |
570 RPC_U32(&msg, 4U);
571
572 if (addr_end)
573 *addr_end = ((u64)RPC_U32(&msg, 8U) << 32U) |
574 RPC_U32(&msg, 12U);
575
576 return ret;
577}
578
579sc_bool_t sc_rm_is_resource_owned(sc_ipc_t ipc, sc_rsrc_t resource)
580{
581 struct udevice *dev = gd->arch.scu_dev;
582 int size = sizeof(struct sc_rpc_msg_s);
583 struct sc_rpc_msg_s msg;
584 int ret;
585 u8 result;
586
587 if (!dev)
588 hang();
589
590 RPC_VER(&msg) = SC_RPC_VERSION;
591 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
592 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_RESOURCE_OWNED;
593 RPC_U16(&msg, 0U) = (u16)resource;
594 RPC_SIZE(&msg) = 2U;
595
596 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
597 result = RPC_R8(&msg);
598 if (result != 0 && result != 1) {
599 printf("%s: resource:%d res:%d\n",
600 __func__, resource, RPC_R8(&msg));
601 if (ret)
602 printf("%s: res:%d res:%d\n", __func__, resource,
603 RPC_R8(&msg));
604 }
605
606 return !!result;
607}
Peng Fand4191db2019-09-23 10:12:31 +0000608
609int sc_rm_partition_alloc(sc_ipc_t ipc, sc_rm_pt_t *pt, sc_bool_t secure,
610 sc_bool_t isolated, sc_bool_t restricted,
611 sc_bool_t grant, sc_bool_t coherent)
612{
613 struct udevice *dev = gd->arch.scu_dev;
614 struct sc_rpc_msg_s msg;
615 int size = sizeof(struct sc_rpc_msg_s);
616 int ret;
617
618 RPC_VER(&msg) = SC_RPC_VERSION;
619 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
620 RPC_FUNC(&msg) = (u8)RM_FUNC_PARTITION_ALLOC;
621 RPC_U8(&msg, 0U) = B2U8(secure);
622 RPC_U8(&msg, 1U) = B2U8(isolated);
623 RPC_U8(&msg, 2U) = B2U8(restricted);
624 RPC_U8(&msg, 3U) = B2U8(grant);
625 RPC_U8(&msg, 4U) = B2U8(coherent);
626 RPC_SIZE(&msg) = 3U;
627
628 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
629 if (ret) {
630 printf("%s: secure:%u isolated:%u restricted:%u grant:%u coherent:%u res:%d\n",
631 __func__, secure, isolated, restricted, grant, coherent,
632 RPC_R8(&msg));
633 }
634
635 if (pt)
636 *pt = RPC_U8(&msg, 0U);
637
638 return ret;
639}
640
641int sc_rm_partition_free(sc_ipc_t ipc, sc_rm_pt_t pt)
642{
643 struct udevice *dev = gd->arch.scu_dev;
644 struct sc_rpc_msg_s msg;
645 int size = sizeof(struct sc_rpc_msg_s);
646 int ret;
647
648 RPC_VER(&msg) = SC_RPC_VERSION;
649 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
650 RPC_FUNC(&msg) = (u8)RM_FUNC_PARTITION_FREE;
651 RPC_U8(&msg, 0U) = (u8)pt;
652 RPC_SIZE(&msg) = 2U;
653
654 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
655 if (ret) {
656 printf("%s: pt:%u res:%d\n",
657 __func__, pt, RPC_R8(&msg));
658 }
659
660 return ret;
661}
662
663int sc_rm_get_partition(sc_ipc_t ipc, sc_rm_pt_t *pt)
664{
665 struct udevice *dev = gd->arch.scu_dev;
666 struct sc_rpc_msg_s msg;
667 int size = sizeof(struct sc_rpc_msg_s);
668 int ret;
669
670 RPC_VER(&msg) = SC_RPC_VERSION;
671 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
672 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_PARTITION;
673 RPC_SIZE(&msg) = 1U;
674
675 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
676 if (ret)
677 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
678
679 if (pt)
680 *pt = RPC_U8(&msg, 0U);
681
682 return ret;
683}
684
685int sc_rm_set_parent(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rm_pt_t pt_parent)
686{
687 struct udevice *dev = gd->arch.scu_dev;
688 struct sc_rpc_msg_s msg;
689 int size = sizeof(struct sc_rpc_msg_s);
690 int ret;
691
692 RPC_VER(&msg) = SC_RPC_VERSION;
693 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
694 RPC_FUNC(&msg) = (u8)RM_FUNC_SET_PARENT;
695 RPC_U8(&msg, 0U) = (u8)pt;
696 RPC_U8(&msg, 1U) = (u8)pt_parent;
697 RPC_SIZE(&msg) = 2U;
698
699 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
700 if (ret) {
701 printf("%s: pt:%u, pt_parent:%u, res:%d\n",
702 __func__, pt, pt_parent, RPC_R8(&msg));
703 }
704
705 return ret;
706}
707
708int sc_rm_assign_resource(sc_ipc_t ipc, sc_rm_pt_t pt, sc_rsrc_t resource)
709{
710 struct udevice *dev = gd->arch.scu_dev;
711 struct sc_rpc_msg_s msg;
712 int size = sizeof(struct sc_rpc_msg_s);
713 int ret;
714
715 RPC_VER(&msg) = SC_RPC_VERSION;
716 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
717 RPC_FUNC(&msg) = (u8)RM_FUNC_ASSIGN_RESOURCE;
718 RPC_U16(&msg, 0U) = (u16)resource;
719 RPC_U8(&msg, 2U) = (u8)pt;
720 RPC_SIZE(&msg) = 2U;
721
722 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
723 if (ret) {
724 printf("%s: pt:%u, resource:%u, res:%d\n",
725 __func__, pt, resource, RPC_R8(&msg));
726 }
727
728 return ret;
729}
730
731int sc_rm_assign_pad(sc_ipc_t ipc, sc_rm_pt_t pt, sc_pad_t pad)
732{
733 struct udevice *dev = gd->arch.scu_dev;
734 struct sc_rpc_msg_s msg;
735 int size = sizeof(struct sc_rpc_msg_s);
736 int ret;
737
738 RPC_VER(&msg) = SC_RPC_VERSION;
739 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
740 RPC_FUNC(&msg) = (u8)RM_FUNC_ASSIGN_PAD;
741 RPC_U16(&msg, 0U) = (u16)pad;
742 RPC_U8(&msg, 2U) = (u8)pt;
743 RPC_SIZE(&msg) = 2U;
744
745 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
746 if (ret) {
747 printf("%s: pt:%u, pad:%u, res:%d\n",
748 __func__, pt, pad, RPC_R8(&msg));
749 }
750
751 return ret;
752}
753
754sc_bool_t sc_rm_is_pad_owned(sc_ipc_t ipc, sc_pad_t pad)
755{
756 struct udevice *dev = gd->arch.scu_dev;
757 struct sc_rpc_msg_s msg;
758 int size = sizeof(struct sc_rpc_msg_s);
759 int ret;
760 u8 result;
761
762 RPC_VER(&msg) = SC_RPC_VERSION;
763 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
764 RPC_FUNC(&msg) = (u8)RM_FUNC_IS_PAD_OWNED;
765 RPC_U8(&msg, 0U) = (u8)pad;
766 RPC_SIZE(&msg) = 2U;
767
768 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
769 result = RPC_R8(&msg);
770 if (result != 0 && result != 1) {
771 printf("%s: pad:%d res:%d\n", __func__, pad, RPC_R8(&msg));
772 if (ret) {
773 printf("%s: pad:%d res:%d\n", __func__,
774 pad, RPC_R8(&msg));
775 }
776 }
777
778 return !!result;
779}
780
781int sc_rm_get_resource_owner(sc_ipc_t ipc, sc_rsrc_t resource,
782 sc_rm_pt_t *pt)
783{
784 struct udevice *dev = gd->arch.scu_dev;
785 struct sc_rpc_msg_s msg;
786 int size = sizeof(struct sc_rpc_msg_s);
787 int ret;
788
789 RPC_VER(&msg) = SC_RPC_VERSION;
790 RPC_SVC(&msg) = (u8)SC_RPC_SVC_RM;
791 RPC_FUNC(&msg) = (u8)RM_FUNC_GET_RESOURCE_OWNER;
792 RPC_U16(&msg, 0U) = (u16)resource;
793 RPC_SIZE(&msg) = 2U;
794
795 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
796 if (pt)
797 *pt = RPC_U8(&msg, 0U);
798
799 return ret;
800}
801
802int sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
803 sc_faddr_t address)
804{
805 struct udevice *dev = gd->arch.scu_dev;
806 struct sc_rpc_msg_s msg;
807 int size = sizeof(struct sc_rpc_msg_s);
808 int ret;
809
810 RPC_VER(&msg) = SC_RPC_VERSION;
811 RPC_SVC(&msg) = (u8)SC_RPC_SVC_PM;
812 RPC_FUNC(&msg) = (u8)PM_FUNC_CPU_START;
813 RPC_U32(&msg, 0U) = (u32)(address >> 32ULL);
814 RPC_U32(&msg, 4U) = (u32)address;
815 RPC_U16(&msg, 8U) = (u16)resource;
816 RPC_U8(&msg, 10U) = B2U8(enable);
817 RPC_SIZE(&msg) = 4U;
818
819 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
820 if (ret) {
821 printf("%s: resource:%d address:0x%llx: res:%d\n",
822 __func__, resource, address, RPC_R8(&msg));
823 }
824
825 return ret;
826}
827
828int sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
829 sc_pm_power_mode_t *mode)
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_GET_RESOURCE_POWER_MODE;
839 RPC_U16(&msg, 0U) = (u16)resource;
840 RPC_SIZE(&msg) = 2U;
841
842 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
843 if (ret) {
844 printf("%s: resource:%d: res:%d\n",
845 __func__, resource, RPC_R8(&msg));
846 }
847
848 if (mode)
849 *mode = RPC_U8(&msg, 0U);
850
851 return ret;
852}
853
854int sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
855 sc_faddr_t addr)
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_SECO;
864 RPC_FUNC(&msg) = (u8)SECO_FUNC_AUTHENTICATE;
865 RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL);
866 RPC_U32(&msg, 4U) = (u32)addr;
867 RPC_U8(&msg, 8U) = (u8)cmd;
868 RPC_SIZE(&msg) = 4U;
869
870 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
871 if (ret)
872 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
873
874 return ret;
875}
876
877int sc_seco_forward_lifecycle(sc_ipc_t ipc, u32 change)
878{
879 struct udevice *dev = gd->arch.scu_dev;
880 struct sc_rpc_msg_s msg;
881 int size = sizeof(struct sc_rpc_msg_s);
882 int ret;
883
884 RPC_VER(&msg) = SC_RPC_VERSION;
885 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
886 RPC_FUNC(&msg) = (u8)SECO_FUNC_FORWARD_LIFECYCLE;
887 RPC_U32(&msg, 0U) = (u32)change;
888 RPC_SIZE(&msg) = 2U;
889
890 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
891 if (ret) {
892 printf("%s: change:%u, res:%d\n", __func__,
893 change, RPC_R8(&msg));
894 }
895
896 return ret;
897}
898
899int sc_seco_chip_info(sc_ipc_t ipc, u16 *lc, u16 *monotonic, u32 *uid_l,
900 u32 *uid_h)
901{
902 struct udevice *dev = gd->arch.scu_dev;
903 struct sc_rpc_msg_s msg;
904 int size = sizeof(struct sc_rpc_msg_s);
905 int ret;
906
907 RPC_VER(&msg) = SC_RPC_VERSION;
908 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
909 RPC_FUNC(&msg) = (u8)SECO_FUNC_CHIP_INFO;
910 RPC_SIZE(&msg) = 1U;
911
912 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
913 if (ret)
914 printf("%s: res:%d\n", __func__, RPC_R8(&msg));
915
916 if (uid_l)
917 *uid_l = RPC_U32(&msg, 0U);
918
919 if (uid_h)
920 *uid_h = RPC_U32(&msg, 4U);
921
922 if (lc)
923 *lc = RPC_U16(&msg, 8U);
924
925 if (monotonic)
926 *monotonic = RPC_U16(&msg, 10U);
927
928 return ret;
929}
930
931void sc_seco_build_info(sc_ipc_t ipc, u32 *version, u32 *commit)
932{
933 struct udevice *dev = gd->arch.scu_dev;
934 struct sc_rpc_msg_s msg;
935 int size = sizeof(struct sc_rpc_msg_s);
936
937 RPC_VER(&msg) = SC_RPC_VERSION;
938 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
939 RPC_FUNC(&msg) = (u8)(SECO_FUNC_BUILD_INFO);
940 RPC_SIZE(&msg) = 1U;
941
942 misc_call(dev, SC_FALSE, &msg, size, &msg, size);
943
944 if (version)
945 *version = RPC_U32(&msg, 0U);
946
947 if (commit)
948 *commit = RPC_U32(&msg, 4U);
949}
950
951int sc_seco_get_event(sc_ipc_t ipc, u8 idx, u32 *event)
952{
953 struct udevice *dev = gd->arch.scu_dev;
954 struct sc_rpc_msg_s msg;
955 int size = sizeof(struct sc_rpc_msg_s);
956 int ret;
957
958 RPC_VER(&msg) = SC_RPC_VERSION;
959 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
960 RPC_FUNC(&msg) = (u8)SECO_FUNC_GET_EVENT;
961 RPC_U8(&msg, 0U) = (u8)idx;
962 RPC_SIZE(&msg) = 2U;
963
964 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
965 if (ret)
966 printf("%s: idx: %u, res:%d\n", __func__, idx, RPC_R8(&msg));
967
968 if (event)
969 *event = RPC_U32(&msg, 0U);
970
971 return ret;
972}
973
974int sc_seco_gen_key_blob(sc_ipc_t ipc, u32 id, sc_faddr_t load_addr,
975 sc_faddr_t export_addr, u16 max_size)
976{
977 struct udevice *dev = gd->arch.scu_dev;
978 struct sc_rpc_msg_s msg;
979 int size = sizeof(struct sc_rpc_msg_s);
980 int ret;
981
982 RPC_VER(&msg) = SC_RPC_VERSION;
983 RPC_SVC(&msg) = (u8)SC_RPC_SVC_SECO;
984 RPC_FUNC(&msg) = (u8)SECO_FUNC_GEN_KEY_BLOB;
985 RPC_U32(&msg, 0U) = (u32)(load_addr >> 32ULL);
986 RPC_U32(&msg, 4U) = (u32)load_addr;
987 RPC_U32(&msg, 8U) = (u32)(export_addr >> 32ULL);
988 RPC_U32(&msg, 12U) = (u32)export_addr;
989 RPC_U32(&msg, 16U) = (u32)id;
990 RPC_U16(&msg, 20U) = (u16)max_size;
991 RPC_SIZE(&msg) = 7U;
992
993 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
994 if (ret) {
995 printf("%s: id: %u, load_addr 0x%llx, export_addr 0x%llx, res:%d\n",
996 __func__, id, load_addr, export_addr, RPC_R8(&msg));
997 }
998
999 return ret;
1000}
Breno Lima184c7e22019-10-16 18:10:54 -03001001
1002int sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr,
1003 u16 dst_size)
1004{
1005 struct udevice *dev = gd->arch.scu_dev;
1006 struct sc_rpc_msg_s msg;
1007 int size = sizeof(struct sc_rpc_msg_s);
1008 int ret;
1009
1010 RPC_VER(&msg) = SC_RPC_VERSION;
1011 RPC_SIZE(&msg) = 4U;
1012 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1013 RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_MP_KEY);
1014
1015 RPC_U32(&msg, 0U) = (u32)(dst_addr >> 32ULL);
1016 RPC_U32(&msg, 4U) = (u32)(dst_addr);
1017 RPC_U16(&msg, 8U) = (u16)(dst_size);
1018
1019 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1020 if (ret)
1021 printf("%s, dst_addr:0x%llx, res:%d\n",
1022 __func__, dst_addr, RPC_R8(&msg));
1023
1024 return ret;
1025}
1026
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +02001027int sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, u8 size_m,
1028 u8 lock)
Breno Lima184c7e22019-10-16 18:10:54 -03001029{
1030 struct udevice *dev = gd->arch.scu_dev;
1031 struct sc_rpc_msg_s msg;
1032 int size = sizeof(struct sc_rpc_msg_s);
1033 int ret;
1034
1035 RPC_VER(&msg) = SC_RPC_VERSION;
1036 RPC_SIZE(&msg) = 4U;
1037 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1038 RPC_FUNC(&msg) = (u8)(SECO_FUNC_UPDATE_MPMR);
1039
1040 RPC_U32(&msg, 0U) = (u32)(addr >> 32ULL);
1041 RPC_U32(&msg, 4U) = (u32)(addr);
1042 RPC_U8(&msg, 8U) = (u8)(size_m);
1043 RPC_U8(&msg, 9U) = (u8)(lock);
1044
1045 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1046 if (ret)
1047 printf("%s, addr:0x%llx, size_m:%x, lock:0x%x, res:%d\n",
1048 __func__, addr, size_m, lock, RPC_R8(&msg));
1049 return ret;
1050}
1051
1052int sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr,
1053 u16 msg_size, sc_faddr_t dst_addr,
1054 u16 dst_size)
1055{
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) = 6U;
1063 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1064 RPC_FUNC(&msg) = (u8)(SECO_FUNC_GET_MP_SIGN);
1065
1066 RPC_U32(&msg, 0U) = (u32)(msg_addr >> 32ULL);
1067 RPC_U32(&msg, 4U) = (u32)(msg_addr);
1068 RPC_U32(&msg, 8U) = (u32)(dst_addr >> 32ULL);
1069 RPC_U32(&msg, 12U) = (u32)(dst_addr);
1070 RPC_U16(&msg, 16U) = (u16)(msg_size);
1071 RPC_U16(&msg, 18U) = (u16)(dst_size);
1072
1073 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1074 if (ret)
1075 printf("%s, msg_addr:0x%llx, msg_size:%x, dst_addr:0x%llx,"
1076 "dst_size:%x, res:%d\n", __func__, msg_addr, msg_size,
1077 dst_addr, dst_size, RPC_R8(&msg));
1078
1079 return ret;
1080}
Ye Li24b5dae2019-11-13 21:20:43 -08001081
Franck LENORMANDd3b70ea2019-10-09 10:27:43 +02001082int sc_seco_secvio_config(sc_ipc_t ipc, u8 id, u8 access,
1083 u32 *data0, u32 *data1, u32 *data2, u32 *data3,
1084 u32 *data4, u8 size)
1085{
1086 struct udevice *dev = gd->arch.scu_dev;
1087 struct sc_rpc_msg_s msg;
1088 int msg_size = sizeof(struct sc_rpc_msg_s);
1089 int ret;
1090
1091 RPC_VER(&msg) = SC_RPC_VERSION;
1092 RPC_SIZE(&msg) = 7U;
1093 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1094 RPC_FUNC(&msg) = (u8)(SECO_FUNC_SECVIO_CONFIG);
1095
1096 RPC_U32(&msg, 0U) = (u32)(*data0);
1097 RPC_U32(&msg, 4U) = (u32)(*data1);
1098 RPC_U32(&msg, 8U) = (u32)(*data2);
1099 RPC_U32(&msg, 12U) = (u32)(*data3);
1100 RPC_U32(&msg, 16U) = (u32)(*data4);
1101 RPC_U8(&msg, 20U) = (u8)(id);
1102 RPC_U8(&msg, 21U) = (u8)(access);
1103 RPC_U8(&msg, 22U) = (u8)(size);
1104
1105 ret = misc_call(dev, SC_FALSE, &msg, msg_size, &msg, msg_size);
1106 if (ret)
1107 printf("%s, id:0x%x, access:%x, res:%d\n",
1108 __func__, id, access, RPC_R8(&msg));
1109
1110 *data0 = (u32)RPC_U32(&msg, 0U);
1111 *data1 = (u32)RPC_U32(&msg, 4U);
1112 *data2 = (u32)RPC_U32(&msg, 8U);
1113 *data3 = (u32)RPC_U32(&msg, 12U);
1114 *data4 = (u32)RPC_U32(&msg, 16U);
1115
1116 return ret;
1117}
1118
1119int sc_seco_secvio_dgo_config(sc_ipc_t ipc, u8 id, u8 access, u32 *data)
Ye Li24b5dae2019-11-13 21:20:43 -08001120{
1121 struct udevice *dev = gd->arch.scu_dev;
1122 struct sc_rpc_msg_s msg;
1123 int size = sizeof(struct sc_rpc_msg_s);
1124 int ret;
1125
1126 RPC_VER(&msg) = SC_RPC_VERSION;
1127 RPC_SIZE(&msg) = 3U;
1128 RPC_SVC(&msg) = (u8)(SC_RPC_SVC_SECO);
1129 RPC_FUNC(&msg) = (u8)(SECO_FUNC_SECVIO_DGO_CONFIG);
1130
1131 RPC_U32(&msg, 0U) = (u32)(*data);
1132 RPC_U8(&msg, 4U) = (u8)(id);
1133 RPC_U8(&msg, 5U) = (u8)(access);
1134
1135 ret = misc_call(dev, SC_FALSE, &msg, size, &msg, size);
1136 if (ret)
1137 printf("%s, id:0x%x, access:%x, res:%d\n",
1138 __func__, id, access, RPC_R8(&msg));
1139
1140 if (data)
1141 *data = RPC_U32(&msg, 0U);
1142
1143 return ret;
1144}