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