1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2017-2020 NXP
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * o Redistributions of source code must retain the above copyright notice, this list
11 * of conditions and the following disclaimer.
12 *
13 * o Redistributions in binary form must reproduce the above copyright notice, this
14 * list of conditions and the following disclaimer in the documentation and/or
15 * other materials provided with the distribution.
16 *
17 * o Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
25 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*!
34 * File containing client-side RPC functions for the SECO service. These
35 * functions are ported to clients that communicate to the SC.
36 *
37 * @addtogroup SECO_SVC
38 * @{
39 */
40
41 /* Includes */
42
43 #include "main/types.h"
44 #include "svc/rm/rm_api.h"
45 #include "svc/seco/seco_api.h"
46 #include "../../main/rpc.h"
47 #include "svc/seco/seco_rpc.h"
48
49 /* Local Defines */
50
51 /* Local Types */
52
53 /* Local Functions */
54
sc_seco_image_load(sc_ipc_t ipc,sc_faddr_t addr_src,sc_faddr_t addr_dst,uint32_t len,sc_bool_t fw)55 sc_err_t sc_seco_image_load(sc_ipc_t ipc, sc_faddr_t addr_src,
56 sc_faddr_t addr_dst, uint32_t len, sc_bool_t fw)
57 {
58 sc_rpc_msg_t msg;
59 sc_err_t err;
60
61 RPC_VER(&msg) = SC_RPC_VERSION;
62 RPC_SIZE(&msg) = 7U;
63 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
64 RPC_FUNC(&msg) = U8(SECO_FUNC_IMAGE_LOAD);
65
66 RPC_U32(&msg, 0U) = U32(addr_src >> 32ULL);
67 RPC_U32(&msg, 4U) = U32(addr_src);
68 RPC_U32(&msg, 8U) = U32(addr_dst >> 32ULL);
69 RPC_U32(&msg, 12U) = U32(addr_dst);
70 RPC_U32(&msg, 16U) = U32(len);
71 RPC_U8(&msg, 20U) = B2U8(fw);
72
73 sc_call_rpc(ipc, &msg, SC_FALSE);
74
75 err = (sc_err_t) RPC_R8(&msg);
76
77 return err;
78 }
79
sc_seco_authenticate(sc_ipc_t ipc,sc_seco_auth_cmd_t cmd,sc_faddr_t addr)80 sc_err_t sc_seco_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
81 sc_faddr_t addr)
82 {
83 sc_rpc_msg_t msg;
84 sc_err_t err;
85
86 RPC_VER(&msg) = SC_RPC_VERSION;
87 RPC_SIZE(&msg) = 4U;
88 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
89 RPC_FUNC(&msg) = U8(SECO_FUNC_AUTHENTICATE);
90
91 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
92 RPC_U32(&msg, 4U) = U32(addr);
93 RPC_U8(&msg, 8U) = U8(cmd);
94
95 sc_call_rpc(ipc, &msg, SC_FALSE);
96
97 err = (sc_err_t) RPC_R8(&msg);
98
99 return err;
100 }
101
sc_seco_enh_authenticate(sc_ipc_t ipc,sc_seco_auth_cmd_t cmd,sc_faddr_t addr,uint32_t mask1,uint32_t mask2)102 sc_err_t sc_seco_enh_authenticate(sc_ipc_t ipc, sc_seco_auth_cmd_t cmd,
103 sc_faddr_t addr, uint32_t mask1, uint32_t mask2)
104 {
105 sc_rpc_msg_t msg;
106 sc_err_t err;
107
108 RPC_VER(&msg) = SC_RPC_VERSION;
109 RPC_SIZE(&msg) = 6U;
110 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
111 RPC_FUNC(&msg) = U8(SECO_FUNC_ENH_AUTHENTICATE);
112
113 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
114 RPC_U32(&msg, 4U) = U32(addr);
115 RPC_U32(&msg, 8U) = U32(mask1);
116 RPC_U32(&msg, 12U) = U32(mask2);
117 RPC_U8(&msg, 16U) = U8(cmd);
118
119 sc_call_rpc(ipc, &msg, SC_FALSE);
120
121 err = (sc_err_t) RPC_R8(&msg);
122
123 return err;
124 }
125
sc_seco_forward_lifecycle(sc_ipc_t ipc,uint32_t change)126 sc_err_t sc_seco_forward_lifecycle(sc_ipc_t ipc, uint32_t change)
127 {
128 sc_rpc_msg_t msg;
129 sc_err_t err;
130
131 RPC_VER(&msg) = SC_RPC_VERSION;
132 RPC_SIZE(&msg) = 2U;
133 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
134 RPC_FUNC(&msg) = U8(SECO_FUNC_FORWARD_LIFECYCLE);
135
136 RPC_U32(&msg, 0U) = U32(change);
137
138 sc_call_rpc(ipc, &msg, SC_FALSE);
139
140 err = (sc_err_t) RPC_R8(&msg);
141
142 return err;
143 }
144
sc_seco_return_lifecycle(sc_ipc_t ipc,sc_faddr_t addr)145 sc_err_t sc_seco_return_lifecycle(sc_ipc_t ipc, sc_faddr_t addr)
146 {
147 sc_rpc_msg_t msg;
148 sc_err_t err;
149
150 RPC_VER(&msg) = SC_RPC_VERSION;
151 RPC_SIZE(&msg) = 3U;
152 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
153 RPC_FUNC(&msg) = U8(SECO_FUNC_RETURN_LIFECYCLE);
154
155 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
156 RPC_U32(&msg, 4U) = U32(addr);
157
158 sc_call_rpc(ipc, &msg, SC_FALSE);
159
160 err = (sc_err_t) RPC_R8(&msg);
161
162 return err;
163 }
164
sc_seco_commit(sc_ipc_t ipc,uint32_t * info)165 sc_err_t sc_seco_commit(sc_ipc_t ipc, uint32_t *info)
166 {
167 sc_rpc_msg_t msg;
168 sc_err_t err;
169
170 RPC_VER(&msg) = SC_RPC_VERSION;
171 RPC_SIZE(&msg) = 2U;
172 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
173 RPC_FUNC(&msg) = U8(SECO_FUNC_COMMIT);
174
175 RPC_U32(&msg, 0U) = U32(*info);
176
177 sc_call_rpc(ipc, &msg, SC_FALSE);
178
179 err = (sc_err_t) RPC_R8(&msg);
180
181 *info = (uint32_t) RPC_U32(&msg, 0U);
182
183 return err;
184 }
185
sc_seco_attest_mode(sc_ipc_t ipc,uint32_t mode)186 sc_err_t sc_seco_attest_mode(sc_ipc_t ipc, uint32_t mode)
187 {
188 sc_rpc_msg_t msg;
189 sc_err_t err;
190
191 RPC_VER(&msg) = SC_RPC_VERSION;
192 RPC_SIZE(&msg) = 2U;
193 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
194 RPC_FUNC(&msg) = U8(SECO_FUNC_ATTEST_MODE);
195
196 RPC_U32(&msg, 0U) = U32(mode);
197
198 sc_call_rpc(ipc, &msg, SC_FALSE);
199
200 err = (sc_err_t) RPC_R8(&msg);
201
202 return err;
203 }
204
sc_seco_attest(sc_ipc_t ipc,uint64_t nonce)205 sc_err_t sc_seco_attest(sc_ipc_t ipc, uint64_t nonce)
206 {
207 sc_rpc_msg_t msg;
208 sc_err_t err;
209
210 RPC_VER(&msg) = SC_RPC_VERSION;
211 RPC_SIZE(&msg) = 3U;
212 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
213 RPC_FUNC(&msg) = U8(SECO_FUNC_ATTEST);
214
215 RPC_U32(&msg, 0U) = U32(nonce >> 32ULL);
216 RPC_U32(&msg, 4U) = U32(nonce);
217
218 sc_call_rpc(ipc, &msg, SC_FALSE);
219
220 err = (sc_err_t) RPC_R8(&msg);
221
222 return err;
223 }
224
sc_seco_get_attest_pkey(sc_ipc_t ipc,sc_faddr_t addr)225 sc_err_t sc_seco_get_attest_pkey(sc_ipc_t ipc, sc_faddr_t addr)
226 {
227 sc_rpc_msg_t msg;
228 sc_err_t err;
229
230 RPC_VER(&msg) = SC_RPC_VERSION;
231 RPC_SIZE(&msg) = 3U;
232 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
233 RPC_FUNC(&msg) = U8(SECO_FUNC_GET_ATTEST_PKEY);
234
235 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
236 RPC_U32(&msg, 4U) = U32(addr);
237
238 sc_call_rpc(ipc, &msg, SC_FALSE);
239
240 err = (sc_err_t) RPC_R8(&msg);
241
242 return err;
243 }
244
sc_seco_get_attest_sign(sc_ipc_t ipc,sc_faddr_t addr)245 sc_err_t sc_seco_get_attest_sign(sc_ipc_t ipc, sc_faddr_t addr)
246 {
247 sc_rpc_msg_t msg;
248 sc_err_t err;
249
250 RPC_VER(&msg) = SC_RPC_VERSION;
251 RPC_SIZE(&msg) = 3U;
252 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
253 RPC_FUNC(&msg) = U8(SECO_FUNC_GET_ATTEST_SIGN);
254
255 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
256 RPC_U32(&msg, 4U) = U32(addr);
257
258 sc_call_rpc(ipc, &msg, SC_FALSE);
259
260 err = (sc_err_t) RPC_R8(&msg);
261
262 return err;
263 }
264
sc_seco_attest_verify(sc_ipc_t ipc,sc_faddr_t addr)265 sc_err_t sc_seco_attest_verify(sc_ipc_t ipc, sc_faddr_t addr)
266 {
267 sc_rpc_msg_t msg;
268 sc_err_t err;
269
270 RPC_VER(&msg) = SC_RPC_VERSION;
271 RPC_SIZE(&msg) = 3U;
272 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
273 RPC_FUNC(&msg) = U8(SECO_FUNC_ATTEST_VERIFY);
274
275 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
276 RPC_U32(&msg, 4U) = U32(addr);
277
278 sc_call_rpc(ipc, &msg, SC_FALSE);
279
280 err = (sc_err_t) RPC_R8(&msg);
281
282 return err;
283 }
284
sc_seco_gen_key_blob(sc_ipc_t ipc,uint32_t id,sc_faddr_t load_addr,sc_faddr_t export_addr,uint16_t max_size)285 sc_err_t sc_seco_gen_key_blob(sc_ipc_t ipc, uint32_t id, sc_faddr_t load_addr,
286 sc_faddr_t export_addr, uint16_t max_size)
287 {
288 sc_rpc_msg_t msg;
289 sc_err_t err;
290
291 RPC_VER(&msg) = SC_RPC_VERSION;
292 RPC_SIZE(&msg) = 7U;
293 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
294 RPC_FUNC(&msg) = U8(SECO_FUNC_GEN_KEY_BLOB);
295
296 RPC_U32(&msg, 0U) = U32(load_addr >> 32ULL);
297 RPC_U32(&msg, 4U) = U32(load_addr);
298 RPC_U32(&msg, 8U) = U32(export_addr >> 32ULL);
299 RPC_U32(&msg, 12U) = U32(export_addr);
300 RPC_U32(&msg, 16U) = U32(id);
301 RPC_U16(&msg, 20U) = U16(max_size);
302
303 sc_call_rpc(ipc, &msg, SC_FALSE);
304
305 err = (sc_err_t) RPC_R8(&msg);
306
307 return err;
308 }
309
sc_seco_load_key(sc_ipc_t ipc,uint32_t id,sc_faddr_t addr)310 sc_err_t sc_seco_load_key(sc_ipc_t ipc, uint32_t id, sc_faddr_t addr)
311 {
312 sc_rpc_msg_t msg;
313 sc_err_t err;
314
315 RPC_VER(&msg) = SC_RPC_VERSION;
316 RPC_SIZE(&msg) = 4U;
317 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
318 RPC_FUNC(&msg) = U8(SECO_FUNC_LOAD_KEY);
319
320 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
321 RPC_U32(&msg, 4U) = U32(addr);
322 RPC_U32(&msg, 8U) = U32(id);
323
324 sc_call_rpc(ipc, &msg, SC_FALSE);
325
326 err = (sc_err_t) RPC_R8(&msg);
327
328 return err;
329 }
330
sc_seco_get_mp_key(sc_ipc_t ipc,sc_faddr_t dst_addr,uint16_t dst_size)331 sc_err_t sc_seco_get_mp_key(sc_ipc_t ipc, sc_faddr_t dst_addr,
332 uint16_t dst_size)
333 {
334 sc_rpc_msg_t msg;
335 sc_err_t err;
336
337 RPC_VER(&msg) = SC_RPC_VERSION;
338 RPC_SIZE(&msg) = 4U;
339 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
340 RPC_FUNC(&msg) = U8(SECO_FUNC_GET_MP_KEY);
341
342 RPC_U32(&msg, 0U) = U32(dst_addr >> 32ULL);
343 RPC_U32(&msg, 4U) = U32(dst_addr);
344 RPC_U16(&msg, 8U) = U16(dst_size);
345
346 sc_call_rpc(ipc, &msg, SC_FALSE);
347
348 err = (sc_err_t) RPC_R8(&msg);
349
350 return err;
351 }
352
sc_seco_update_mpmr(sc_ipc_t ipc,sc_faddr_t addr,uint8_t size,uint8_t lock)353 sc_err_t sc_seco_update_mpmr(sc_ipc_t ipc, sc_faddr_t addr, uint8_t size,
354 uint8_t lock)
355 {
356 sc_rpc_msg_t msg;
357 sc_err_t err;
358
359 RPC_VER(&msg) = SC_RPC_VERSION;
360 RPC_SIZE(&msg) = 4U;
361 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
362 RPC_FUNC(&msg) = U8(SECO_FUNC_UPDATE_MPMR);
363
364 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
365 RPC_U32(&msg, 4U) = U32(addr);
366 RPC_U8(&msg, 8U) = U8(size);
367 RPC_U8(&msg, 9U) = U8(lock);
368
369 sc_call_rpc(ipc, &msg, SC_FALSE);
370
371 err = (sc_err_t) RPC_R8(&msg);
372
373 return err;
374 }
375
sc_seco_get_mp_sign(sc_ipc_t ipc,sc_faddr_t msg_addr,uint16_t msg_size,sc_faddr_t dst_addr,uint16_t dst_size)376 sc_err_t sc_seco_get_mp_sign(sc_ipc_t ipc, sc_faddr_t msg_addr,
377 uint16_t msg_size, sc_faddr_t dst_addr, uint16_t dst_size)
378 {
379 sc_rpc_msg_t msg;
380 sc_err_t err;
381
382 RPC_VER(&msg) = SC_RPC_VERSION;
383 RPC_SIZE(&msg) = 6U;
384 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
385 RPC_FUNC(&msg) = U8(SECO_FUNC_GET_MP_SIGN);
386
387 RPC_U32(&msg, 0U) = U32(msg_addr >> 32ULL);
388 RPC_U32(&msg, 4U) = U32(msg_addr);
389 RPC_U32(&msg, 8U) = U32(dst_addr >> 32ULL);
390 RPC_U32(&msg, 12U) = U32(dst_addr);
391 RPC_U16(&msg, 16U) = U16(msg_size);
392 RPC_U16(&msg, 18U) = U16(dst_size);
393
394 sc_call_rpc(ipc, &msg, SC_FALSE);
395
396 err = (sc_err_t) RPC_R8(&msg);
397
398 return err;
399 }
400
sc_seco_build_info(sc_ipc_t ipc,uint32_t * version,uint32_t * commit)401 void sc_seco_build_info(sc_ipc_t ipc, uint32_t *version, uint32_t *commit)
402 {
403 sc_rpc_msg_t msg;
404
405 RPC_VER(&msg) = SC_RPC_VERSION;
406 RPC_SIZE(&msg) = 1U;
407 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
408 RPC_FUNC(&msg) = U8(SECO_FUNC_BUILD_INFO);
409
410 sc_call_rpc(ipc, &msg, SC_FALSE);
411
412 if (version != NULL)
413 {
414 *version = (uint32_t) RPC_U32(&msg, 0U);
415 }
416 if (commit != NULL)
417 {
418 *commit = (uint32_t) RPC_U32(&msg, 4U);
419 }
420 }
421
sc_seco_chip_info(sc_ipc_t ipc,uint16_t * lc,uint16_t * monotonic,uint32_t * uid_l,uint32_t * uid_h)422 sc_err_t sc_seco_chip_info(sc_ipc_t ipc, uint16_t *lc, uint16_t *monotonic,
423 uint32_t *uid_l, uint32_t *uid_h)
424 {
425 sc_rpc_msg_t msg;
426 sc_err_t err;
427
428 RPC_VER(&msg) = SC_RPC_VERSION;
429 RPC_SIZE(&msg) = 1U;
430 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
431 RPC_FUNC(&msg) = U8(SECO_FUNC_CHIP_INFO);
432
433 sc_call_rpc(ipc, &msg, SC_FALSE);
434
435 err = (sc_err_t) RPC_R8(&msg);
436
437 if (uid_l != NULL)
438 {
439 *uid_l = (uint32_t) RPC_U32(&msg, 0U);
440 }
441 if (uid_h != NULL)
442 {
443 *uid_h = (uint32_t) RPC_U32(&msg, 4U);
444 }
445 if (lc != NULL)
446 {
447 *lc = (uint16_t) RPC_U16(&msg, 8U);
448 }
449 if (monotonic != NULL)
450 {
451 *monotonic = (uint16_t) RPC_U16(&msg, 10U);
452 }
453
454 return err;
455 }
456
sc_seco_enable_debug(sc_ipc_t ipc,sc_faddr_t addr)457 sc_err_t sc_seco_enable_debug(sc_ipc_t ipc, sc_faddr_t addr)
458 {
459 sc_rpc_msg_t msg;
460 sc_err_t err;
461
462 RPC_VER(&msg) = SC_RPC_VERSION;
463 RPC_SIZE(&msg) = 3U;
464 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
465 RPC_FUNC(&msg) = U8(SECO_FUNC_ENABLE_DEBUG);
466
467 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
468 RPC_U32(&msg, 4U) = U32(addr);
469
470 sc_call_rpc(ipc, &msg, SC_FALSE);
471
472 err = (sc_err_t) RPC_R8(&msg);
473
474 return err;
475 }
476
sc_seco_get_event(sc_ipc_t ipc,uint8_t idx,uint32_t * event)477 sc_err_t sc_seco_get_event(sc_ipc_t ipc, uint8_t idx, uint32_t *event)
478 {
479 sc_rpc_msg_t msg;
480 sc_err_t err;
481
482 RPC_VER(&msg) = SC_RPC_VERSION;
483 RPC_SIZE(&msg) = 2U;
484 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
485 RPC_FUNC(&msg) = U8(SECO_FUNC_GET_EVENT);
486
487 RPC_U8(&msg, 0U) = U8(idx);
488
489 sc_call_rpc(ipc, &msg, SC_FALSE);
490
491 err = (sc_err_t) RPC_R8(&msg);
492
493 if (event != NULL)
494 {
495 *event = (uint32_t) RPC_U32(&msg, 0U);
496 }
497
498 return err;
499 }
500
sc_seco_fuse_write(sc_ipc_t ipc,sc_faddr_t addr)501 sc_err_t sc_seco_fuse_write(sc_ipc_t ipc, sc_faddr_t addr)
502 {
503 sc_rpc_msg_t msg;
504 sc_err_t err;
505
506 RPC_VER(&msg) = SC_RPC_VERSION;
507 RPC_SIZE(&msg) = 3U;
508 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
509 RPC_FUNC(&msg) = U8(SECO_FUNC_FUSE_WRITE);
510
511 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
512 RPC_U32(&msg, 4U) = U32(addr);
513
514 sc_call_rpc(ipc, &msg, SC_FALSE);
515
516 err = (sc_err_t) RPC_R8(&msg);
517
518 return err;
519 }
520
sc_seco_patch(sc_ipc_t ipc,sc_faddr_t addr)521 sc_err_t sc_seco_patch(sc_ipc_t ipc, sc_faddr_t addr)
522 {
523 sc_rpc_msg_t msg;
524 sc_err_t err;
525
526 RPC_VER(&msg) = SC_RPC_VERSION;
527 RPC_SIZE(&msg) = 3U;
528 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
529 RPC_FUNC(&msg) = U8(SECO_FUNC_PATCH);
530
531 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
532 RPC_U32(&msg, 4U) = U32(addr);
533
534 sc_call_rpc(ipc, &msg, SC_FALSE);
535
536 err = (sc_err_t) RPC_R8(&msg);
537
538 return err;
539 }
540
sc_seco_set_mono_counter_partition(sc_ipc_t ipc,uint16_t * she)541 sc_err_t sc_seco_set_mono_counter_partition(sc_ipc_t ipc, uint16_t *she)
542 {
543 sc_rpc_msg_t msg;
544 sc_err_t err;
545
546 RPC_VER(&msg) = SC_RPC_VERSION;
547 RPC_SIZE(&msg) = 2U;
548 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
549 RPC_FUNC(&msg) = U8(SECO_FUNC_SET_MONO_COUNTER_PARTITION);
550
551 RPC_U16(&msg, 0U) = U16(*she);
552
553 sc_call_rpc(ipc, &msg, SC_FALSE);
554
555 err = (sc_err_t) RPC_R8(&msg);
556
557 *she = (uint16_t) RPC_U16(&msg, 0U);
558
559 return err;
560 }
561
sc_seco_set_fips_mode(sc_ipc_t ipc,uint8_t mode,uint32_t * reason)562 sc_err_t sc_seco_set_fips_mode(sc_ipc_t ipc, uint8_t mode, uint32_t *reason)
563 {
564 sc_rpc_msg_t msg;
565 sc_err_t err;
566
567 RPC_VER(&msg) = SC_RPC_VERSION;
568 RPC_SIZE(&msg) = 2U;
569 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
570 RPC_FUNC(&msg) = U8(SECO_FUNC_SET_FIPS_MODE);
571
572 RPC_U8(&msg, 0U) = U8(mode);
573
574 sc_call_rpc(ipc, &msg, SC_FALSE);
575
576 err = (sc_err_t) RPC_R8(&msg);
577
578 if (reason != NULL)
579 {
580 *reason = (uint32_t) RPC_U32(&msg, 0U);
581 }
582
583 return err;
584 }
585
sc_seco_start_rng(sc_ipc_t ipc,sc_seco_rng_stat_t * status)586 sc_err_t sc_seco_start_rng(sc_ipc_t ipc, sc_seco_rng_stat_t *status)
587 {
588 sc_rpc_msg_t msg;
589 sc_err_t err;
590
591 RPC_VER(&msg) = SC_RPC_VERSION;
592 RPC_SIZE(&msg) = 1U;
593 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
594 RPC_FUNC(&msg) = U8(SECO_FUNC_START_RNG);
595
596 sc_call_rpc(ipc, &msg, SC_FALSE);
597
598 err = (sc_err_t) RPC_R8(&msg);
599
600 if (status != NULL)
601 {
602 *status = (sc_seco_rng_stat_t) RPC_U32(&msg, 0U);
603 }
604
605 return err;
606 }
607
sc_seco_sab_msg(sc_ipc_t ipc,sc_faddr_t addr)608 sc_err_t sc_seco_sab_msg(sc_ipc_t ipc, sc_faddr_t addr)
609 {
610 sc_rpc_msg_t msg;
611 sc_err_t err;
612
613 RPC_VER(&msg) = SC_RPC_VERSION;
614 RPC_SIZE(&msg) = 3U;
615 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
616 RPC_FUNC(&msg) = U8(SECO_FUNC_SAB_MSG);
617
618 RPC_U32(&msg, 0U) = U32(addr >> 32ULL);
619 RPC_U32(&msg, 4U) = U32(addr);
620
621 sc_call_rpc(ipc, &msg, SC_FALSE);
622
623 err = (sc_err_t) RPC_R8(&msg);
624
625 return err;
626 }
627
sc_seco_secvio_enable(sc_ipc_t ipc)628 sc_err_t sc_seco_secvio_enable(sc_ipc_t ipc)
629 {
630 sc_rpc_msg_t msg;
631 sc_err_t err;
632
633 RPC_VER(&msg) = SC_RPC_VERSION;
634 RPC_SIZE(&msg) = 1U;
635 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
636 RPC_FUNC(&msg) = U8(SECO_FUNC_SECVIO_ENABLE);
637
638 sc_call_rpc(ipc, &msg, SC_FALSE);
639
640 err = (sc_err_t) RPC_R8(&msg);
641
642 return err;
643 }
644
sc_seco_secvio_config(sc_ipc_t ipc,uint8_t id,uint8_t access,uint32_t * data0,uint32_t * data1,uint32_t * data2,uint32_t * data3,uint32_t * data4,uint8_t size)645 sc_err_t sc_seco_secvio_config(sc_ipc_t ipc, uint8_t id, uint8_t access,
646 uint32_t *data0, uint32_t *data1, uint32_t *data2, uint32_t *data3,
647 uint32_t *data4, uint8_t size)
648 {
649 sc_rpc_msg_t msg;
650 sc_err_t err;
651
652 RPC_VER(&msg) = SC_RPC_VERSION;
653 RPC_SIZE(&msg) = 7U;
654 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
655 RPC_FUNC(&msg) = U8(SECO_FUNC_SECVIO_CONFIG);
656
657 RPC_U32(&msg, 0U) = U32(*data0);
658 RPC_U32(&msg, 4U) = U32(*data1);
659 RPC_U32(&msg, 8U) = U32(*data2);
660 RPC_U32(&msg, 12U) = U32(*data3);
661 RPC_U32(&msg, 16U) = U32(*data4);
662 RPC_U8(&msg, 20U) = U8(id);
663 RPC_U8(&msg, 21U) = U8(access);
664 RPC_U8(&msg, 22U) = U8(size);
665
666 sc_call_rpc(ipc, &msg, SC_FALSE);
667
668 err = (sc_err_t) RPC_R8(&msg);
669
670 *data0 = (uint32_t) RPC_U32(&msg, 0U);
671 *data1 = (uint32_t) RPC_U32(&msg, 4U);
672 *data2 = (uint32_t) RPC_U32(&msg, 8U);
673 *data3 = (uint32_t) RPC_U32(&msg, 12U);
674 *data4 = (uint32_t) RPC_U32(&msg, 16U);
675
676 return err;
677 }
678
sc_seco_secvio_dgo_config(sc_ipc_t ipc,uint8_t id,uint8_t access,uint32_t * data)679 sc_err_t sc_seco_secvio_dgo_config(sc_ipc_t ipc, uint8_t id, uint8_t access,
680 uint32_t *data)
681 {
682 sc_rpc_msg_t msg;
683 sc_err_t err;
684
685 RPC_VER(&msg) = SC_RPC_VERSION;
686 RPC_SIZE(&msg) = 3U;
687 RPC_SVC(&msg) = U8(SC_RPC_SVC_SECO);
688 RPC_FUNC(&msg) = U8(SECO_FUNC_SECVIO_DGO_CONFIG);
689
690 RPC_U32(&msg, 0U) = U32(*data);
691 RPC_U8(&msg, 4U) = U8(id);
692 RPC_U8(&msg, 5U) = U8(access);
693
694 sc_call_rpc(ipc, &msg, SC_FALSE);
695
696 err = (sc_err_t) RPC_R8(&msg);
697
698 *data = (uint32_t) RPC_U32(&msg, 0U);
699
700 return err;
701 }
702
703 /**@}*/
704
705