blob: 09ef7b5ba3dcbe9620fb049ad43cdff66e5a6dfd [file] [log] [blame]
Jorge Ramirez-Ortiz166363f2021-02-14 16:27:23 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2021, Foundries.IO
4 *
5 */
6
Tom Rinid678a592024-05-18 20:20:43 -06007#include <common.h>
Jorge Ramirez-Ortiz166363f2021-02-14 16:27:23 +01008#include <scp03.h>
9#include <tee.h>
10#include <tee/optee_ta_scp03.h>
Jorge Ramirez-Ortiz166363f2021-02-14 16:27:23 +010011
12static int scp03_enable(bool provision)
13{
14 const struct tee_optee_ta_uuid uuid = PTA_SCP03_UUID;
15 struct tee_open_session_arg session;
16 struct tee_invoke_arg invoke;
17 struct tee_param param;
18 struct udevice *tee = NULL;
19
20 tee = tee_find_device(tee, NULL, NULL, NULL);
21 if (!tee)
22 return -ENODEV;
23
24 memset(&session, 0, sizeof(session));
25 tee_optee_ta_uuid_to_octets(session.uuid, &uuid);
26 if (tee_open_session(tee, &session, 0, NULL))
27 return -ENXIO;
28
29 memset(&param, 0, sizeof(param));
30 param.attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
31 param.u.value.a = provision;
32
33 memset(&invoke, 0, sizeof(invoke));
34 invoke.func = PTA_CMD_ENABLE_SCP03;
35 invoke.session = session.session;
36
37 if (tee_invoke_func(tee, &invoke, 1, &param))
38 return -EIO;
39
40 tee_close_session(tee, session.session);
41
42 return 0;
43}
44
45int tee_enable_scp03(void)
46{
47 return scp03_enable(false);
48}
49
50int tee_provision_scp03(void)
51{
52 return scp03_enable(true);
53}