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